如何将GPS坐标转换为完整的地址与PHP?

如何将GPS坐标转换为完整的地址与PHP?

问题描述:

我有GPS坐标形式54.1456123 10.413456如何将GPS坐标转换为完整的地址与PHP?

如何将它们与PHP转换为邮政编码,街道和城市地址?

+0

尝试谷歌地图API [参考此帖] [1] [1]: http://*.com/questions/10441521/get-address-from-google-map-api-v3-in-english – limovala 2013-05-06 09:10:43

+0

这不是重复的:这里我问如何实现t他用PHP。 – rubo77 2013-05-07 12:31:31

使用谷歌API

$lat="54.1456123"; 
$long = "10.413456"; 

$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&sensor=false"; 

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_HEADER, false); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_ENCODING, ""); 
$curlData = curl_exec($curl); 
curl_close($curl); 

$address = json_decode($curlData); 
print_r($address); 
+0

您可能需要使用Google API注册 - 并从中获取keyws等。 – 2013-05-06 09:08:46

+1

我试过了,没有使用Google API密钥,也没有curl:'$ curlData = file_get_contents(\t $ url);'工作正常,谢谢 – rubo77 2013-05-06 09:13:45

+0

只限于有限的查询 – Muhaimin 2017-05-18 08:18:51

没有curl也不API密钥需要:

function geo2address($lat,$long) { 
    $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&sensor=false"; 
    $curlData=file_get_contents( $url); 
    $address = json_decode($curlData); 
    $a=$address->results[0]; 
    return explode(",",$a->formatted_address); 
}