$fulladdress = 'South Bay Hospital 4016 Sun City Center Blvd Sun City Center Florida 33573';
$address = str_replace(' ','+',$fulladdress);
$url = "http://maps.googleapis.com/maps/api/geocode/json?address='".@urlencode($address)."'&sensor=false";
$result_string = @file_get_contents($url);<br>
$result = @json_decode($result_string, true);<br>
$result1[]=@$result['results'][0];<br>
$result2[]=$result1[0]['geometry'];<br>
$result3[]=$result2[0]['location'];<br>
return $result3[0];
我正在使用此 Google Geocode API 获取纬度和经度。我已通过完整地址“South Bay Hospital 4016 Sun City Center Blvd Sun City Centre Florida 33573”,但未提供完整地址纬度和经度。 当我检查 print_r($result) 时。所以它会自动删除“South Bay Hospital”并为“4016 Sun City Center Blvd Sun City Centre Florida 33573”提供纬度和经度,这就是谷歌地图标记不在正确位置的原因。
最佳答案
检查这个:
// We get the JSON results from this request
$geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
// We convert the JSON to an array
$geo = json_decode($geo, true);
// If everything is cool
if ($geo['status'] = 'OK') {
// We set our values
$latitude = $geo['results'][0]['geometry']['location']['lat'];
$longitude = $geo['results'][0]['geometry']['location']['lng'];
}
关于php - 没有得到正确的经纬度和完整地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33887573/