Sorry! - I confused myself and probably you by talking about
setTimeout in this context - I was thinking about the use of
setTimeout to slow the rate of directionsRequests or geocoding so as
not to fall foul of the request limits.
Rossko is right that you have to wait for the result before you use
it, and I guess that means putting all your processing and further
requests after each response status=OK
This is how I think it should be done. I'd be interested in opinions
on if this overview is the best way, or if there are others:
Note - this is just example code, going from Daniels original, to
illustrate the method, so its not tested, but if the general idea is
correct, I'll put up an example using it, so that others can see it in
a working form.
// taking an address from a form input
var start = document.getElementById("address").value;
// taking Daniels carParkLocation array as above
firstEnd = new google.maps.LatLng(carParkLocation[0][0],
carParkLocation[0][1]);
firstRequest = {
origin: start,
destination: firstEnd
};
var arrayCount = 0;
// call the request function for the first time
makeRequest(firstRequest);
function makeRequest(requestVar) {
directionsService.route(requestVar, function (response,status) {
if (status == google.maps.DirectionsStatus.OK) {
// do whatever stuff with response
// then go through rest of car park locations Array
arrayCount ++;
if (arrayCount < carParkLocation.length) {
var nextEnd = new
google.maps.LatLng(carParkLocation[arrayCount][0],
carParkLocation[arrayCount][1]);
nextRequest = {
origin: start,
destination: nextEnd
};
// recursive call to the request function
makeRequest(nextRequest);
}
else {
// finished all in the array
}
}
else {
// status didn't return OK
}
});
On Oct 20, 2:51 pm, Rossko <[email protected]> wrote:
> > I believe I am storing the results in the callback?
>
> Yes, but you are trying to display them before they have returned.
> Looking at
--
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.