I'm trying to dynamically get the driving distances of many locations
with the following function:
function getDrivingDistance(location){
var distance;
var request = {
origin: startingPosition,
destination: location,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
distance=response.routes[0].legs[0].distance.text;
}
});
return distance;
}
This doesn't return anything and I can't set the values of any global
variables inside the "function (response, status)". I know it works
because when I put somediv.setInnerHTML= distance it updates the DOM
and shows distances, but I can't set any global variables inside that
function. Does anyone know of a solution or any other way to return
the driving distance between two points?
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.