<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-
microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example: Advanced Directions</title>
<script src="http://maps.google.com/maps?
file=api&v=2&key=YOURKEY" type="text/javascript"></script>
<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);
}
}
function setDirections(fromAddress, toAddress, betweenAddresses) {
document.getElementById("getDistance").innerHTML = "";
if (betweenAddresses!="") {betweenAddresses = " to: " +
betweenAddresses.replace(/;/g," to: ");} else {betweenAddresses="";}
gdir.load("from: " + fromAddress +betweenAddresses+" to: " +
toAddress, {getSteps:true});
}
function onGDirectionsLoad(){
var totalDis = 0;
for (var i=0; i<gdir.getNumRoutes(); i++) {
var route = gdir.getRoute(i);
var geocode = route.getStartGeocode();
var geocode2 = route.getEndGeocode();
document.getElementById("getDistance").innerHTML += geocode.address
+ " - " + geocode2.address + ": " + route.getDistance().html +"<br /
>";
}
document.getElementById("getDistance").innerHTML += "TOTAL: " +
gdir.getDistance().html;
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<h2>Distance Calculator</h2>
<div id="getDistance"></div>
<form action="#" onsubmit="setDirections(this.from.value,
this.to.value, this.betweenAddresses.value); return false">
From: <input type="text" size="25" id="fromAddress" name="from"
value="Zalaegerszeg"/><br />
To:<input type="text" size="25" id="toAddress" name="to"
value="Budapest" /><br />
Kitero:<input type="text" size="25" id="betweenAddresses"
name="kitero" value="Keszthely;Szekesfehervar"/><br />
<input name="submit" type="submit" value="Get Directions!" />
</from>
<div id="directions" style="width: 275px; display:none;"></div>
<div id="map_canvas" style="width: 310px; height:
400px;display:none;"></div>
</body>
</html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---