0

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);

}
Mike
  • 254
  • 1
  • 6
  • 16
  • 1
    Client side services have additional per session quota. You have 50 QPS only for web service calls, from client side service you have initial bucket of 10 requests, once bucket is empty you can execute 1 request per second. Have a look at this answer: https://stackoverflow.com/a/42876576/5140781 – xomena Nov 20 '19 at 23:06
  • Thanks @xomena, I'll have a look into that. Appreciate the link to another answer. – Mike Nov 21 '19 at 10:29

0 Answers0