它每次移動地圖時都會進入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
}
}
任何想法是什麼造成的問題?
您已評論更新textview上文本的行! – Shubhank
我還有一個日誌 – bhaskar
,你看到logcat中的日誌? – Shubhank