fix crash when Geocoder has no internet connection

This commit is contained in:
Johan von Forstner
2021-12-30 14:12:59 +01:00
parent dc4c2394f9
commit ec7b08338c

View File

@@ -908,7 +908,11 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
} else if (locationName != null) {
lifecycleScope.launch {
val address = withContext(Dispatchers.IO) {
Geocoder(requireContext()).getFromLocationName(locationName, 1).getOrNull(0)
try {
Geocoder(requireContext()).getFromLocationName(locationName, 1).getOrNull(0)
} catch (e: IOException) {
null
}
}
address?.let {
val latLng = LatLng(it.latitude, it.longitude)