Created
June 5, 2021 15:28
-
-
Save hkawii/90ad7a5aa3f5d0fc05174cb98c57d40d 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 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