簡體   English   中英

cURL地理編碼OVER_QUERY_LIMIT

[英]cURL Geocode OVER_QUERY_LIMIT

我對Google的地址解析api有疑問:

我有一個地址,應該使用cURL通過google geocoding api轉換為緯度和經度。 您將在下面看到我的代碼。 它工作正常,但是突然停止工作,我得到了“ OVER_QUERY_LIMIT”答案。 我查了一下,如果每天請求api超過2500次,通常會發生這種情況。 這是不可能的,因為我的網站正在整理中,每天大約有20-40個地理編碼請求。

那么,發生“ OVER_QUERY_LIMIT”的真正問題是什么? 我的代碼被Google某種程度上阻止了嗎?!

ini_set('allow_url_fopen', true);

$CookiePath = 'mycookiepath/geocookie.txt';
$userAgent = "mysite.com";
$ListURLRoot = "http://maps.googleapis.com/maps/api/geocode/json";
$ListURLSuffix = '&sensor=false';
$Curl_Obj = curl_init(); // Setup cURL
curl_setopt($Curl_Obj, CURLOPT_COOKIEJAR, $CookiePath);
curl_setopt($Curl_Obj, CURLOPT_USERAGENT, $userAgent);
curl_setopt($Curl_Obj, CURLOPT_HEADER, 0);
curl_setopt($Curl_Obj, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($Curl_Obj, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($Curl_Obj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($Curl_Obj, CURLOPT_TIMEOUT, 30);
curl_setopt($Curl_Obj, CURLOPT_POST, 0); 



$stAddr = str_replace(' ','+', $ast);
$City = str_replace(' ','+', $ac);
$address = "$stAddr,+$City,+{$aco},+{$ap}";
$address = str_replace(' ', '+', $address);
$ListURL = "{$ListURLRoot}?address=$address$ListURLSuffix";
curl_setopt ($Curl_Obj, CURLOPT_URL, $ListURL);
$output = curl_exec ($Curl_Obj);
GetLocation($output);

function GetLocation($output)  {
    global $db_connect;
    $Loc = json_decode($output, true);
    if(isset($Loc))  {
        $i = 1;
        while ($Loc['status']=="OVER_QUERY_LIMIT") {
            if ($i > 14) {
                echo "Geocode failed!";
                exit();
            }
            sleep(1);
            $i++;

        }
        if(isset($Loc['status']) && stristr($Loc['status'], 'OK'))  {
            if(isset($Loc['results'][0]['geometry']['location']))  {
                $Lat = $Loc['results'][0]['geometry']['location']['lat'];
                $Lng = $Loc['results'][0]['geometry']['location']['lng'];
            }
        }
        else {
            error_log($Loc['status'], 0);
            echo "Unknown error occured!";
            exit();
        }
    }
}

提前致謝!

通常,這是Google的問題。 嘗試避免服務器端地理編碼。 而是使用客戶端javascript解算器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM