0

I try to implement reverse geocoding in Android App. But when I call getFromLocation() function, it doesn't return value. Can Someone see my code and tell me where I might make mistakes?

public void getAddress(Location location) {
    Geocoder geo_coder = new Geocoder(this, Locale.ENGLISH);
    try {
        List<Address> address = geo_coder.getFromLocation(location.getLatitude(),
                location.getLongitude(), 1);
        Toast.makeText(this, Double.toString(location.getLongitude()), Toast.LENGTH_LONG).show();
        Toast.makeText(this, Double.toString(location.getLatitude()), Toast.LENGTH_LONG).show();
        if (address != null && address.size() > 0) {
            textAddr.setText(address.get(0).getFeatureName() + ", " + 
        address.get(0).getLocality() + ", " + address.get(0).getAdminArea() + 
        ", " + address.get(0).getCountryName());
        }
        else {
            textAddr.setText("Waiting for Location!");
        }
    }
    catch (IOException e) {
        e.printStackTrace();    
    }
}

The toast can show the right latitude and longitude, but I can't get the real address

2
Contributors
1
Reply
8
Views
3 Years
Discussion Span
Last Post by Masterblank
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.