编程语言
首页 > 编程语言> > php – 谷歌地理编码API错误:超越极限

php – 谷歌地理编码API错误:超越极限

作者:互联网

我目前正在使用Google地理编码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";
}

解决方法:

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

标签:php,google-geocoder,google-geocoding-api
来源: https://codeday.me/bug/20190624/1283208.html