Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting sub locality null for some lat long?

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
like image 821
Vishal Vaishnav Avatar asked May 08 '19 11:05

Vishal Vaishnav


1 Answers

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.

like image 67
ismail alaoui Avatar answered Oct 05 '22 00:10

ismail alaoui