【问题标题】:Google Geocoding API Error: OVER QUERY LIMITGoogle 地理编码 API 错误:超出查询限制
【发布时间】:2013-07-24 19:47:30
【问题描述】:

我目前正在使用 Google Geocoding API,并且非常谨慎地使用它。限制是每天 2500 个查询,我最多可能在 20-50 个范围内。然后在过去的一周里每隔一段时间我就会收到一个 OVER_QUERY_LIMIT 错误。我一次只处理 1 个地址,没有循环或任何东西。它只进行一次地理编码并将 lat/lng 发送到数据库,之后它只会被数据库引用。谁能告诉我为什么会出现这个错误?

$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$siteAddress."&sensor=true";

直到大约一周前,这在一个多月的测试中完美运行。

我有几个页面做同样的事情,但只是在不同的时间出于不同的目的被引用。这是地理编码的所有代码。

  $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$siteAddress."&sensor=true"; // the request URL you'll send to google to get back your XML feed
$xml = simplexml_load_file($request_url) or die("url not loading");// XML request
$status = $xml->status;// GET the request status as google's api can return several responses
if ($status=="OK") {
    //request returned completed time to get lat / lang for storage
    $lat = $xml->result->geometry->location->lat;
    $long = $xml->result->geometry->location->lng;
echo "latitude:$lat, longitude:$long <br>";
    echo "$lat, $long <br>";  //spit out results or you can store them in a DB if you wish
}
if ($status=="ZERO_RESULTS") {
    //indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
$errorcode = "ZERO RESULTS";
echo "ZERO RESULTS";
}
if ($status=="OVER_QUERY_LIMIT") {
    //indicates that you are over your quota of geocode requests against the google api
$errorcode = "Over Query Limit";
echo "Over Query Limit";
}
if ($status=="REQUEST_DENIED") {
    //indicates that your request was denied, generally because of lack of a sensor parameter.
$errorcode = "Request Denied";
echo "Request Denied";
}
if ($status=="INVALID_REQUEST") {
    //generally indicates that the query (address or latlng) is missing.
$errorcode = "Invalid Request";
echo "Invalid Request";
}

【问题讨论】:

    标签: php google-geocoder google-geocoding-api


    【解决方案1】:

    Google Geocoding API 有每日限制,但它也限制了您提出请求的速度。在地理编码调用之间放置一个sleep(1) 调用,你可能会没事(如果没有,请尝试再增加几秒钟)。

    【讨论】:

    • 我尝试将 sleep(1) 放在地理编码调用之前(因为只有一个),但它仍然返回 OVER_QUERY_LIMIT
    • 您可能会被阻止一两个小时,如果最初不起作用,请再次尝试大于 1 的内容。
    • 很遗憾,这不起作用。 Google 是否对地理编码设置了任何其他限制?
    【解决方案2】:

    地理编码的每日限制为 2,500,但也受到限制。因此,正如其他人所建议的那样,在您的 PHP 代码中每 10 条记录编写一次 sleep(1) 语句。您可能还想编写一个队列模块/进程来控制请求。将结果缓存到地址缓存模块或其他缓存类型中。

    另外,您是否考虑过您的 IP 地址上的其他域/用户? SugarCRM 的 SugarOnDemand 有这个问题。太多的用户,共享相同的 IP 地址,同时尝试对地址进行地理编码可能会导致可怕的 OVER_QUERY_LIMIT 问题。

    要有耐心。如果上述方法不起作用。买一台安装了 WAMP 服务器的笔记本电脑,然后去当地启用 WIFI 的咖啡店。它们通常具有不同的 IP 地址,因此您每天可以对 2500*5 进行地理编码。这很痛苦,但它有效。

    如果您真的想发挥创意,请编写一个代理脚本 (PHP) 以将 CURL 请求从不同的 IP 地址(某个其他域)退回。 Google 的地理编码 API 会认为请求来自代理脚本的 IP 地址。

    【讨论】:

    • 我们也可以使用VPN来隐藏我们的IP吗?
    • 您可以使用 VPN 或其他代理方法来更改请求的 IP 地址。
    【解决方案3】:
    $output= json_decode(stripslashes(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$data['lat'].','.$data[ 'lon'].'&sensor=false&language=ru')));
    打印 $output->results[0]->formatted_address
    睡眠(2);

    【讨论】:

    • 这类似于现有答案,只是它没有提供任何解释并获取 formatted_address 字段。你应该编辑你的答案,让它更明显。
    【解决方案4】:

    某些非典型或格式错误的地址字符串仍会引发此错误。

    截至本文发布时,以散列 # 字符开头的某些地址字符串会导致 OVER_QUERY_LIMIT 状态响应。

    如果您知道自己处于 API 调用限制和使用情况下,尤其是如果您有 Google 的计费帐户,我会寻找不寻常的字符 - 特别是地址字符串的开头。

    在大多数情况下,公寓/单元号会成为地址数据,删除有问题的子字符串不会影响位置很多

    【讨论】:

      猜你喜欢
      • 2015-10-15
      • 2016-09-21
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多