UMAR UMAR - 1 year ago 130
Android Question

How to get city name from latitude and longitude coordinates in Google Maps?

How might I obtain the city name in Google Maps if I have latitude and longitude coordinates of a town or area?

I tried using the latitude, longitude and I got country but I don't know how to get city name.

Answer Source

From a Geocoder object, you can call the getFromLocation(double, double, int) method. It will return a list of Address objects that have a method getLocality().

Geocoder gcd = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(lat, lng, 1);
if (addresses.size() > 0) 
   // do your staff
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download