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

$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) 调用,您可能会没事(如果没有,请尝试将其增加几秒钟)。

关于php - 谷歌地理编码 API 错误 : OVER QUERY LIMIT,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17843536/

10-16 18:35