Created
April 11, 2023 15:40
-
-
Save RaheemJnr/0215a6265abcdc47b890b6d185e89901 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getReadableLocation(latitude: Double, longitude: Double, context: Context): String { | |
var addressText = "" | |
val geocoder = Geocoder(context, Locale.getDefault()) | |
try { | |
val addresses = geocoder.getFromLocation(latitude, longitude, 1) | |
if (addresses?.isNotEmpty() == true) { | |
val address = addresses[0] | |
addressText = "${address.getAddressLine(0)}, ${address.locality}" | |
// Use the addressText in your app | |
Log.d("geolocation", addressText) | |
} | |
} catch (e: IOException) { | |
Log.d("geolocation", e.message.toString()) | |
} | |
return addressText | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment