2016-05-17 47 views
1

它每次移動地圖時都會進入onLocationChanged塊,並且新的緯度和長度也會被提取,但它不會更新地址,但會顯示首次加載的地址。我是使用以下更新地址:Geocoder無法更新地址,使用時更改經度和經度

@Override 
public void onLocationChanged(Location location) { 

    Log.e("change" , "change"); 

    double latitude = location.getLatitude(); 
    double longitude = location.getLongitude(); 

    try { 
     Geocoder geo = new Geocoder(this, Locale.getDefault()); 
     List<Address> addresses = geo.getFromLocation(latitude, longitude, 1); 
     if (addresses.isEmpty()) { 

      Log.e("TAG", "Waiting for Location"); 
     } 
     else { 
      if (addresses.size() > 0) { 
       Log.e("TAG", addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() + ", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName()); 
       //yourtextfieldname.setText(addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName()); 
       //Toast.makeText(getApplicationContext(), "Address:- " + addresses.get(0).getFeatureName() + addresses.get(0).getAdminArea() + addresses.get(0).getLocality(), Toast.LENGTH_LONG).show(); 
      } 
     } 
    } 
    catch (Exception e) { 
     e.printStackTrace(); // getFromLocation() may sometimes fail 
    } 


} 

任何想法是什麼造成的問題?

+0

您已評論更新textview上文本的行! – Shubhank

+0

我還有一個日誌 – bhaskar

+0

,你看到logcat中的日誌? – Shubhank

回答

1

地理編碼器在某些設備上不可用,請使用Google API客戶端代替地理編碼器

+0

如何使用?你能幫我 – bhaskar

+0

http://stackoverflow.com/questions/2296377/how-to-get-city-name-from-latitude-and-longitude-coordinates-in-google-maps 請通過這個鏈接,它會幫助你 –