Hi,
When i call showLocation() method multiple times in a loop then
function is not calculate distance the code is as follow
var geocoder, location1, location2, gDir,add1,add2;
function initialize(){
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "", function() {
var drivingDistanceMiles = gDir.getDistance().meters /
1609.344;
var drivingDistanceKilometers =
gDir.getDistance().meters / 1000;
document.getElementById('results').innerHTML =
'<strong>Address 1:
</strong>' + location1.address + ' (' + location1.lat + ':' +
location1.lon + ')<br /><strong>Address 2: </strong>' +
location2.address + ' (' + location2.lat + ':' + location2.lon +
')<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles +
' miles (or ' + drivingDistanceKilometers + ' kilometers)';
});
}
function showLocation(a,b)
{
geocoder.getLocations(a, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the
first address");
}
else
{
location1 = {lat:
response.Placemark[0].Point.coordinates[1], lon:
response.Placemark[0].Point.coordinates[0], address:
response.Placemark[0].address};
geocoder.getLocations(b, function (response) {
if (!response || response.Status.code
!= 200)
{
alert("Sorry, we were unable to
geocode the second address");
}
else
{
location2 = {lat:
response.Placemark[0].Point.coordinates[1],
lon: response.Placemark[0].Point.coordinates[0], address:
response.Placemark[0].address};
gDir.load('from: ' +
location1.address + ' to: ' +
location2.address);
}
});
}
});
}
--
You received this message because you are subscribed to the Google Groups
"Google Maps API V2" 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.