谷歌地理编码API错误:超过查询限制


Google Geocoding API Error: OVER QUERY LIMIT

我目前正在使用Google Geocoding API,并且使用得很少。限制是每天2500次查询,我可能最多在20-50之间。在过去的一周里,我每隔一段时间就会收到一个OVER_QUERY_LMIT错误。我一次只处理一个地址,没有循环或任何东西。它只进行一次地理编码,并将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";
}

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

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

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

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

如果你真的想发挥创意,可以写一个代理脚本(PHP)来从不同的IP地址(其他域)弹出CURL请求。谷歌的地理编码API会认为请求来自代理脚本的IP地址。

$output=json_decode(stripslaches(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng="$data['lat'].','$数据['lon']'&sensor=false&language=ru'));打印$output->结果[0]->格式化地址睡眠(2)

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

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

如果你知道你受API调用限制和使用,特别是如果你在谷歌有一个付费帐户,我会寻找不寻常的字符,尤其是地址字符串的开头。

在大多数情况下,公寓/单元号会进入地址数据,删除有问题的子字符串不会对位置产生太大影响。