Crie um arquivo maps.php com esse código:
<head>
<script src=" http://maps.google.com/?file=api&v=2.x&key=<?=$key?>" type="text/javascript"></script>
<style type="text/css">
table.directions th {
background-color:#EEEEEE;
}
</style>
<script type="text/javascript">
var map;
var gdir;
var geocoder = null;
var addressMarker;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
setDirections("<?=$endereco?>", "<?=$endereco?>", "pt_BR");
}
}
function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: " + toAddress ,{ "locale": locale });
}
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
alert("Local não encontrado! \n Digite: 'Endereço, cidade, estado'");
} else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) {
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
} else if (gdir.getStatus().code == G_GEO_MISSING_QUERY) {
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
} else if (gdir.getStatus().code == G_GEO_BAD_KEY) {
alert("Chave do google maps inválida!");
} else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) {
alert("Local não encontrado! \n Digite: 'Endereço, cidade, estado'");
} else {
alert("Local não encontrado! \n Digite: 'Endereço, cidade, estado'");
}
}
function onGDirectionsLoad(){
// Use this function to access information about the latest load()
// results.
// e.g.
// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
// and yada yada yada...
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<h2>Como Chegar?</h2>
<form action="#" onsubmit="setDirections(this.to.value, '<?=$endereco?>', 'pt_BR'); return false">
<table>
<tr>
<th align="right">
Aonde você está?:
</th>
<td align="right">
<input type="text" size="25" id="toAddress" name="to" value="" />
<input name="submit" type="submit" value="Como chegar" />
</td>
</tr>
</table>
</form>
<br/>
<table class="directions">
<tr>
<th>
Caminho
</th>
<th>
Mapa
</th>
</tr>
<tr>
<td valign="top">
<div id="directions" style="width: 275px; font-size:12px"></div>
</td>
<td valign="top">
<div id="map_canvas" style="width: 530px; height: 400px; "></div>
</td>
</tr>
</table>
</head>
Para funcionar basta definir a variavel $key com o valor da chave do google, e $endereco com o endereço de partida, dar um include nesse arquivo na página que terá o mapa.
Ficando assim:
$key = ABQIAAAAvjzCOu65UhSP8OnS6s02-BTMeaENej-PIhMehfUK6wxvzNIA8RTjeDoqEcmuezo50krh875OX2XDaQ;
$endereco = 'Rua Padre Manoel da Nobrega, 502, Americana, SP';
include('maps.php');
E.. Pronto!