How can I get the current city name in android?

I need to get the name of the current city. If you get the name of the city with AGPS or something good. I need a method or code to get the current city in android. Please share if you know.

+4
source share
2 answers

This is to get the location name from the current lat, long

Geocoder gcd = new Geocoder(context, Locale.getDefault()); List<Address> addresses = gcd.getFromLocation(lat, lng, 1); if (addresses.size() > 0) System.out.println(addresses.get(0).getLocality()); 
+23
source

I have a user370305 answer, but I will just send an alternative just in case.

You can also find the name of the city from your IP address.

Mark this site and this answer here

0
source

Source: https://habr.com/ru/post/1381088/


All Articles