2010-02-12 29 views
1

根據Geocoder documentation,該類將方法提供到可能存在或不存在於設備上的後端服務。如果設備上不存在地址解析器,理論上地理編碼請求將不會返回任何結果。然而,由於沒有後端地理編碼器服務而沒有結果,因爲位置沒有意義,如何區分沒有結果?如何判斷Android設備何時具有Geocoder後端服務?

我的應用程序已經需要Google Maps API,因此這可能是一個爭論點;作爲第二個問題,谷歌地圖API 總是包括一個Geocoder?

回答

2

根據Google Maps docs,「Google地圖API提供了用於地址編碼的客戶端地址解析器」。所以我會說,因爲你需要谷歌地圖API,你需要一個地理編碼器。

4

嚴格來說也可以安裝其他後端,只是嘗試,如果一個地理編碼器存在

final Geocoder geocoder = new Geocoder(this); 
    final String locName = "1600 Amphitheatre Parkway, Mountain View, CA"; 
    try { 
     final List<Address> list = geocoder.getFromLocationName(locName, 1); 
     if (! (list == null || list.isEmpty())) { 
      final Address address = list.get(0); 
      System.out.println("Geocoder backend present, (lat,lon) = (" + address.getLatitude() + ", " + address.getLongitude() + ")"); 
     } 
     else { 
      System.out.println("Geocoder backend not present"); 
     } 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
相關問題