谷歌地理编码API错误:超出限制

时间:2013-07-24 19:47:30

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

我目前正在使用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";
}

4 个答案:

答案 0 :(得分:3)

Google Geocoding API有每日限制,但它也限制了您提出请求的速度。在地理编码调用之间进行sleep(1)调用,您可能会很好(如果没有,请尝试将其增加几秒钟。)

答案 1 :(得分:1)

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

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

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

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

答案 2 :(得分:0)

$output= json_decode(stripslashes(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$data['lat'].','.$data['lon'].'&sensor=false&language=ru')));
print $output->results[0]->formatted_address
sleep(2);

答案 3 :(得分:0)

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

在发布此信息时,某些以哈希字符开头的地址字符串会导致OVER_QUERY_LIMIT状态响应。

如果您知道自己受到API调用限制和使用的限制,特别是如果您在Google帐户中有帐单,我会寻找不寻常的字符-特别是在地址字符串的开头。

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

相关问题