Search code examples
androidgoogle-geocoder

Android Geocoder *suddenly* not returning street address, only city


I have some simple code to return an address from latitude/longitude coordinates. It used to work just fine yesterday, nothing has changed, but today it returns the city instead of the street address.

I know I can dig deeper into the Address class and explicitly call getThoroughfare(), but that would just return null.

Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault());
try {
    List<Address> addresses = geocoder.getFromLocation(lat, lon, 1);
    return addresses.get(0).getAddressLine(0);
}

No emulators, Nexus 5.

Update: it's magic, today the geocoder is working fine again! Note that the longitude/latitude coordinates have remained exactly the same this whole time. Perhaps I'll rely on getThroughfare() to get the street address, but account for the fact that it may not return me a value.


Solution

  • This is due to a reliability issue in the Geocoder service. The longitude/latitude coordinates have remained exactly the same in my unit tests, and from time to time only the city is returned instead of a full address.

    Don't rely on the Geocoder service to always return a full address!