I want to create an app to get a user location like city name , country, etc..I want to city name by current location but I have latitude and longitude. how to get it?
Asked
Active
Viewed 41 times
0
-
what have you tried ? what isn't working ? please add code to your question – a_local_nobody Feb 10 '21 at 07:21
-
You can get the address, city name, the country name by using latitude and longitude check below code. In place of latitude and longitude, you can pass your latitude and longitude. ```val geoCoder = Geocoder(this) val addresses = geoCoder.getFromLocation(latitude, longitude, 1) if (addresses.size > 0) { val address = addresses[0] locationCountry = address?.countryName ?: "" locationState = address?.adminArea ?: "" locationCity = address.locality ?: "``` – Bhojaviya Sagar Feb 10 '21 at 07:24