Thank you. It works fine. On Jun 8, 12:34 pm, William <[email protected]> wrote: > On Jun 8, 7:59 pm, Timo <[email protected]> wrote: > > > > > I think there is a problem with the callback function of the geocoder > > class. > > the loop issues 4 geocoding requests synchronously, but the > asynchronous responses might arrive in a different order. > > The second response might arrive back at the browser before the > first. > > You will need a function to obtain closure on the loop variable and > put the geocodes in the array using this id. > > Also you should keep a count of the responses, and perform post- > processing once all responses are received (instead of the > window.setTimeout with 1 second delay) > > var geocoder; > var n=0; > function geocode(i) { > geocoder.geocode( {'address': Addresses[i][0]}, function(results, > status) { > if (status == google.maps.GeocoderStatus.OK) { > Lat[i-1] = results[0].geometry.location.b; > Lng[i-1] = results[0].geometry.location.c; > } else { > if (status == google.maps.GeocoderStatus.ZERO_RESULTS) { > alert("The address could not be found."); > } else { > alert("Geocode was not successful for the following reason: " > + status); > } > } > n++; > if (n==Addresses.length-1) { > AddInfoWindows(); > changeView(); > } > }); > > } > > ---------------------------------------- > and a loop like this: > > geocoder = new google.maps.Geocoder(); > for(var ii = 1; ii <= Addresses.length-1; ii++) { > geocode(ii); > > } > > ----------------------------------------
-- 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.
