I know there are lots of questions regarding this but I cannot find one that answers my specific question.
Can anybody see something fundamentally wrong with this (there very possible is/must be!)? From my understanding, the limit per second for the Google Geocode API is 50 requests per second. I am running the below code with only about 80 addresses and it throws an error of OVER_QUERY_LIMIT after about 15. The 15 requests are not made in 1 second so why am I getting OVER_QUERY_LIMIT?
I set up the interval because I was facing problems. My understanding of this interval is that it should limit the queries per second to 4 (much less than 50). But still I face the issue!
var done = true;
function geocodeAddress(address, geocoder, resultsMap) {
done = false;
geocoder.geocode({"address": address}, function(results, status) {
if (status === "OK") {
var marker = new google.maps.Marker({
map: resultsMap,
position: results[0].geometry.location
});
} else {
console.error("Geocode on '" + address + "' was not successful for the following reason: ");
console.log(status);
}
done = true;
});
}
function geocodeAll(addresses) {
var addressCount = addresses.length;
var counter = 0;
var next = setInterval(function() {
console.log(counter);
if(done) {
geocodeAddress(addresses[counter], geocoder, map);
counter++;
}
if(!(counter < addressCount)) {
clearInterval(next);
}
}, 250);
}