【问题标题】:Geocoding a list of thousands of addresses对数千个地址的列表进行地理编码
【发布时间】:2013-11-03 23:24:37
【问题描述】:

我是这个论坛的新手。我不是专业开发人员,但我需要将 GPS 坐标与大量地址(超过 1000 个)相关联。我开发了一个简单的 javascript,它可以生成地理编码请求并在日志中显示结果。我注意到在 11 个请求之后它开始返回“over_query_limit”错误。我读到了每秒十个请求的速率限制,所以我在每个请求和以下请求之间插入了一个 1 秒的 sleep(),但这个问题一直困扰着我。有没有人可以帮助我解决这个问题? 谢谢,菲利波

【问题讨论】:

  • 我为什么要等 24 小时?我确定我没有超过每天 2500 个请求的限制...这是您提出建议的原因吗?

标签: javascript api google-maps limit


【解决方案1】:

尝试一次只执行一个请求的函数,并使用setInterval 以每秒 10 次的速度运行该函数。

例子:

//  set some variables
var currentRequest = 0;
var numberOfRequests = 1000;

//  write the function that does one request at the time
function request()
{
    //  request code here, using variable currentRequest

    currentRequest ++;  //  move along one request
}

//  set an interval, so the function runs every tenth of a second (100 ms)
var interval = setInterval(request, 100);

//  and stop the interval if the requests are done
if(currentRequest >= numberOfRequests)
{
    clearInterval(interval);
}

当然,对于数千个请求,这将需要几秒钟,但它应该很好地避免每秒 10 个请求的限制。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多