2014-04-10 61 views
1

這是我的代碼 它沒有任何錯誤,但如何在android中的模擬器上使用緯度和經度獲取完整的地址地址?

它顯示在textView「無地址返回!」

double lat = 18.520430300000000000, log = 73.856743699999920000; 
    String address = null;             
    Geocoder geocoder = new Geocoder(this, Locale.getDefault()); 
    StringBuilder sb = null; 
    try { 
     List<Address> addresses = geocoder.getFromLocation(lat, log, 1); 
     sb = new StringBuilder(); 
     if (addresses.size() > 0) { 

      Address address = addresses.get(0); 

      for (int i = 0; i < address.getMaxAddressLineIndex(); i++) 
       sb.append(address.getAddressLine(i)+ ","); 
      txtAdd.setText("Address :"+sb); 
     } 
     else{ 
      txtAdd.setText("No Address returned!"); 
     } 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     /*e.printStackTrace();*/ 
     txtAdd.setText("Canont get Address!"); 
    } 

PLZ給我這個

在此先感謝解決方案...

回答

0

的數獨給人一種暗示,也許這將有助於

http://developer.android.com/reference/android/location/Geocoder.html

返回一個已知描述區域的地址陣列 immediat只是圍繞着給定的經度和緯度。返回的 地址將針對提供給此類 構造函數的語言環境進行本地化。

返回的值可以通過網絡查找獲得。 結果是一個最佳猜測,不保證是有意義的或 正確。 從您的主UI線程中分別調用 的線程調用此方法可能很有用。

相關問題