如何将GPS坐标转换为完整的地址与PHP?
答
使用谷歌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);
答
没有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);
}
尝试谷歌地图API [参考此帖] [1] [1]: http://*.com/questions/10441521/get-address-from-google-map-api-v3-in-english – limovala 2013-05-06 09:10:43
这不是重复的:这里我问如何实现t他用PHP。 – rubo77 2013-05-07 12:31:31