2013-05-06 115 views
3

我有GPS座標形式54.1456123 10.413456如何將GPS座標轉換爲完整的地址與PHP?

如何將它們與PHP轉換爲郵政編碼,街道和城市地址?

+0

嘗試谷歌地圖API [參考此帖] [1] [1]: http://stackoverflow.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

回答

9

使用谷歌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

6

沒有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); 
} 
相關問題