On Dec 22, 5:19 pm, "[email protected]" <[email protected]> wrote: > On Dec 22, 1:06 pm, KDawg44 <[email protected]> wrote: > > > > > > > > > > > Hi, > > > I am using the JavaScript GoogleMaps API to map out directions. A > > user enters an address and the code cycles through calling for > > distance from the address to each of 8 locations. Then it sorts the > > locations in order of distance, displaying the closest to the user's > > inputted address first. > > > The issue I have is that I want to store the distance from the address > > to each location in the Locations array to be sorted on later (and > > some other stuff). The problem I am having is that the for-loop keeps > > cycling through and the GoogleMap API call does not return until the > > end of the loop, thus, I keep assigning the returned distance to the > > last array element everytime, overwriting it. I end up with only the > > last element having a value, the last value returned. > > > Is there a way to make the call a synchronous call so my code stops > > executing until the GoogleMaps call returns? > > Don't do that. Send the next request in the call back of the previous > call (after pushing the result into your array), another option would > be to use function closure. > > Beware, the directions service is subject to quotas and rate > limiting. Making multiple calls in a loop is not a good idea, it may > work for 8, but not work for 10, and may break unexpectedly, depending > on the load on the servers. To extend it calculate the straight > distance to each of the locations, then only calculate the driving > distance to the closest (some small number) of them. > > > > > Thanks for any help. > > [CODE] > > No > thanks.http://groups.google.com/group/google-maps-js-api-v3/t/2b3f101fd509919e > > -- Larry
Thanks for the suggestions and advice! -- 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.
