-1
現在我正在使用此代碼獲取地址:現在我可以從我的網站PHP上的用戶獲得完整地址嗎?
{
"results" : [
{
"address_components" : [
{
"long_name" : "C 2",
"short_name" : "C 2",
"types" : [ "route" ]
},
{
"long_name" : "Tân Bình",
"short_name" : "Tân Bình",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Hồ Chí Minh",
"short_name" : "Hồ Chí Minh",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Việt Nam",
"short_name" : "VN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "C 2, Tân Bình, Hồ Chí Minh, Việt Nam"
...
"status" : "OK"
}
它缺少街道名稱:
$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);
有結果(簡體你們可以看到完整的結果在這裏:http://maps.googleapis.com/maps/api/geocode/json?latlng=10.8142,106.6438&sensor=false
) 。我想獲得更多信息,例如街道名稱,門牌號碼......我如何獲得用戶的完整地址?
謝謝你們!
我不認爲這個API將能夠準確地返回一個給定的拉特/ lng對的房子號碼。我只是在英格蘭的地址上試過這個地址,並且返回了一系列房屋號碼,而不是實際的號碼 – RamRaider
@Mit Try'&result_type = street_address'。有關參考資料,請參閱[ReverseGeocoding](https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding) –