Below is my code, I am getting null subLocality always ....
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude,longitude, 1);
String suburb = addresses.get(0).getSubLocality();
String state = addresses.get(0).getAdminArea();
String zip = addresses.get(0).getPostalCode();
String country = addresses.get(0).getCountryName();
Log.e("Log for data",""+suburb+" "+state+" "+zip+" "+country);
Below is my response;
null Gujarat 380006 India
Geocoder API will return the values depending on lat
long
, if the API
database doesn't have these values exemple : subLocality
then it will return null
only, in my knowledge there's nothing you can do about it. You have to handle these cases gracefully so your app don't crash.
Handling these cases includes you have to put a check using if
condition is that particular value is null
or it has some value, because if you use any of the value somewhere in code without checking and if that value is null
then app might crash whenever that particular value comes null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With