0
我目前使用此功能反向地理從Instagram的圖片經緯度:谷歌反向地理返回NULL
function getGeoCountry($geoAddress) {
$url = 'http://maps.google.com/maps/api/geocode/json?address=' . $geoAddress .'&sensor=false';
//$get = file_get_contents($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$geoData = json_decode($response);
if(isset($geoData->results[0])) {
foreach($geoData->results[0]->address_components as $addressComponent) {
if(in_array('country', $addressComponent->types)) {
return array($addressComponent->short_name, $addressComponent->long_name);
}
}
}
return null;
}
這很像的60%的時間,但有時返回null。基本上我不知道是什麼原因造成的,我需要有人幫助我解決問題。
在此先感謝