I'm using the Google Maps Javascript API V3 to reverse-geocode a lot of locations (~100) on a page. After about 10 or so, I start getting a 620 error: too many queries.
What's a good way to delay the requests and ensure that they all get completed given that they're asynchronous?
EDIT: Here's what I have so far. It completes all the requests most of the time, but it doesn't retry failed requests.
function replaceAddresses() {
var delay = 0;
$(".lat-lon-address").each(function(index) {
window.setTimeout(queryGeocoder, delay, this);
delay += 1000;
});
}
function queryGeocoder(elem) {
geocoder.getLocations(new GLatLng(
elem.getAttribute("lat"),
elem.getAttribute("lon")),
function(response) {
handleAddress(response, elem);
});
}
function handleAddress(response, elem) {
if (!response || response.Status.code != 200) {
console.log("status code: " + response.Status.code)
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
elem.innerHTML = place.address;
}
}