我正在嘗試將GeoCode從標記檢索到的LatLng反轉爲獲取地址。我很容易獲得街道地址,但getFromLocation()返回的地址永遠不會包含商戶名稱(例如Tim Hortons)。我知道問題不在於座標,因爲當我使用「getFromLocationName()」代替我的代碼的不同部分返回相同的結果時,我得到友好名稱。我看不出爲什麼getFromLocation()的返回值應該與getFromLocationName()的返回值不同。GeoCoder getFromLocation地址永遠不會包含商業名稱
下面是相關的代碼:
private String holderAddress;
...
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
getAddress(marker.getPosition());
...
private void getAddress(LatLng latLng){
Geocoder reverseGeo = new Geocoder(this, Locale.getDefault());
Address processAddress = null;
try {
processAddress = reverseGeo.getFromLocation(latLng.latitude,
latLng.longitude, 1).get(0);
}catch(Exception e){
Log.v("Reverse Geocode failed", e.getMessage());
}
if (processAddress != null) {
holderAddress = processAddress.getAddressLine(0);
} else {
holderAddress = "(" + latLng.latitude + "," + latLng.longitude + ")";
}
}
我曾嘗試檢索多個結果和讀取所有的地址線以及功能名稱。看起來「getFromLocation()」永遠不會返回商業名稱,而「getFromLocationName()」總是設法獲取友好名稱。
任何洞察爲什麼我得到這個結果或可能的解決方法的建議表示讚賞。
謝謝。
'getFromLocation()'的輸入是緯度和經度,而'getFromLocationName()'的輸入是地址名稱。所以結果是不同的。 – ztan