Skip to content

Instantly share code, notes, and snippets.

@hkawii
Created June 5, 2021 15:28
Show Gist options
  • Save hkawii/90ad7a5aa3f5d0fc05174cb98c57d40d to your computer and use it in GitHub Desktop.
Save hkawii/90ad7a5aa3f5d0fc05174cb98c57d40d to your computer and use it in GitHub Desktop.
fun getAddressFromLocation(context: Context): String {
val geocoder = Geocoder(context, Locale.getDefault())
var addresses: List<Address>? = null
val address: Address?
var addressText = ""
try {
addresses = geocoder.getFromLocation(location.value.latitude, location.value.longitude, 1)
}catch(ex: Exception){
ex.printStackTrace()
}
address = addresses?.get(0)
addressText = address?.getAddressLine(0) ?: ""
return addressText
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment