首页 > 解决方案 > OVER_QUERY_LIMIT 谷歌地理编码

问题描述

我知道有很多关于此的问题,但我找不到可以回答我的具体问题的问题。

有人能看出这有什么根本性的问题吗(很可能是/必须是!)?据我了解,Google Geocode API 的每秒限制是每秒 50 个请求。我正在运行以下代码,只有大约 80 个地址,大约 15 个地址后它会引发 OVER_QUERY_LIMIT 错误。15 个请求不是在 1 秒内发出的,为什么我会得到 OVER_QUERY_LIMIT?

我设置了间隔,因为我遇到了问题。我对这个间隔的理解是它应该将每秒查询数限制为 4(远小于 50)。但我仍然面临这个问题!

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

}

标签: javascriptgoogle-geocoding-api

解决方案


推荐阅读