This code save in the variable "drivingDistanceKilometers" the
distance between two points by road:
-----------------------
function distance(p1,p2){
var geocoder, location1, location2, gDir;

        geocoder = new GClientGeocoder();
        gDir = new GDirections();

        geocoder.getLocations(p1, 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(p2);
                        location2 = {lat: 
response.Placemark[0].Point.coordinates[1], lon:
response.Placemark[0].Point.coordinatesGEvent.addListener(gDir,
"load", function() {
                var drivingDistanceKilometers = gDir.getDistance().meters / 
1000;
                alert(drivingDistanceKilometers);
        });[0], address: response.Placemark[0].address};
                        gDir.load('from: ' + p1 + ' to: ' + p2);

                }
        });

        GEvent.addListener(gDir, "load", function() {
                var drivingDistanceKilometers = gDir.getDistance().meters / 
1000;
                alert(drivingDistanceKilometers);
        });
//return  (drivingDistanceKilometers);
}
-----------------------
and run ok but I need return "drivingDistanceKilometers"  to work with
this date.
If I write "return (drivingDistanceKilometers);" in the end function
this return undefined.
How can I return "drivingDistanceKilometers" after event load to not
be undefined?
Thanks.

-- 
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.

Reply via email to