It goes inside onLocationChanged block every time I move the map and new latitude and long is also fetched but it does not update the address but shows the address which was first loaded. I am using the following for updating the address:
@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
}
}