4

我有表格中的 GPS 坐标54.1456123 10.413456

如何使用 PHP 将它们转换为带有邮政编码、街道和城市的地址?

4

2 回答 2

10

使用谷歌 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);
于 2013-05-06T09:08:06.973 回答
6

不需要curlAPI 密钥:

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);
}
于 2013-05-06T10:46:13.770 回答