[英]Reverse Geocoding Responses randomly in php
我已經嘗試過谷歌反向地址解析。以下多次調用for循環的函數...這是隨機工作的...有時響應地址很完美..有時沒有響應...這里是什么問題...
function reversegeo($ilatt,$ilonn)
{
$url1='http://maps.googleapis.com/maps/api/geocode/json?latlng='.$ilatt.','.$ilonn.'&sensor=false';
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url1);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_REFERER, 'http://www.mywebsiteurl.com/Trackfiles/report.php');
$body1 = curl_exec($ch1);
curl_close($ch1);
$json1 = json_decode($body1);
$add=$json1->results[0]->formatted_address;
return $add;
}
您可能經常或太快地訪問服務器。 使用sleep()
在其中添加一些延遲。
另外,當您說“沒有回應”時,您需要更加具體。 如果您擊中的次數過多,Google會給出錯誤代碼,而不僅僅是錯誤。
代替:
$body1 = curl_exec($ch1);
做:
if(($body1 = curl_exec($ch1)) === false) {
echo 'Curl error: ' . curl_error($ch);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.