How to make/handle multiple Google Maps V3 DirectionsRequests? (load listener?)
I have a script that tries to loop through a small array of Google Maps DirectionsRequest objects; I need a way to make the script wait until the DirectionsService responds, so I can save the result before making the next request query. -I know in the older version you could set up something like the following:
directions = new GDirections(null, null);
directions.load("from: " + fromAddr + " to: " + toAddr);
GEvent.addListener(directions, "load", function() {...});
but the v3 documentation seems to deal mostly with listeners for map events (I don't want a map, just directions data). With v3, you have to set a callback function when you call the route() method. Is there an elegant way to pause my loop so it doesn't make a new request query before the previous one gets a response? -Or do I have no choice but to create a new instance of DirectionsService for each query?
Thanks for your help!
开发者_运维问答Carl
In this example http://code.google.com/apis/maps/documentation/javascript/examples/directions-draggable.html you will see the following line:
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
computeTotalDistance(directionsDisplay.directions);
});
I hope this helps. Thanks for asking that question because I wasn't aware of such a listener.
精彩评论