• 我有大约330个entires进行反向地理编码(将lat-lng点转换为街道地址) .

  • 我使用了setInterval函数来延迟发送请求

  • 我在每个请求的1-2秒间隔内随机给出延迟 .

  • 但是一旦反向地理编码达到50,它就会开始抛出QUERY_OVER_LIMIT状态,发送下一个请求所需的延迟会持续指数增加到15-20秒,导致输出在20-30分钟后显示 .

我搜索了大多数stackoverflow问题以及正确阅读谷歌文档仍然没有解决我的问题 .

我还验证了QUERY_OVER_LIMIT状态代码是由于没有请求而不是由于每天2500个请求限制 .

我的项目演示的代码片段(它只是我正在做的一部分,不会运行)

geocoder = new google.maps.Geocoder();
var j = 0;
var area = [];
var time_limit = 1000;
var decoding = setInterval(function() {
  console.log("time is " + time_limit);
  time_limit = Math.floor((Math.random() * 1000) + 1000);
  if (j > (employee_name.length - 1)) {
    for (var k = 0; k < employee_name.length; k++) {
      document.getElementById(k).innerHTML = area[k];
    }
    clearInterval(decoding);
  }
  if (isNaN(employee_address[j].lat) || isNaN(employee_address[j].lng)) {
    console.log("Found At " + j);
    area[j] = "Unknown Location";
    j++;
  } else {
    var point = new google.maps.LatLng(employee_address[j].lat, employee_address[j].lng);
    geocoder.geocode({
      'latLng': point
    }, function(results, status) {
      if (status !== google.maps.GeocoderStatus.OK) {
        console.log(status);
      }
      // This is checking to see if the Geoeode Status is OK before proceeding
      if (status == google.maps.GeocoderStatus.OK) {
        var address = (results[0].formatted_address);
        area.push(address);
        console.log(j);
        j++;
      }
    });
  }
}, time_limit);