2015-10-19 47 views
0

我正在嘗試將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()」總是設法獲取友好名稱。

任何洞察爲什麼我得到這個結果或可能的解決方法的建議表示讚賞。

謝謝。

+0

'getFromLocation()'的輸入是緯度和經度,而'getFromLocationName()'的輸入是地址名稱。所以結果是不同的。 – ztan

回答

0

我的結論是,地理編碼根本無法用於實時地點查詢。雖然有一個getFeatureName()字段,但它似乎只返回對精確GPS座標有用的任何內容,因此放置一個別針幾乎不會產生有用的名字。

我改用Google Places API代替商業名稱查找,爲了一致性,我現在還使用Places API的附近搜索進行搜索而不是地理編碼。