There are 2 things to be aware of:
- The returned values may be obtained by means of a network lookup. It may be useful to call this method from a thread separate from your primary UI thread.
- Possible
IOException
if the network is unavailable or any other I/O problem occurs - The returned addresses will be localized for the locale provided to this class's constructor.
launch { val geocoder = Geocoder(context, Locale.US) try { val results = geocoder.getFromLocation(lat, lng, 1) if (results.size > 0) { val address = results[0] // so something } } catch (e: IOException) { e.printStackTrace() }}
NOTE: I use android kotlin coroutine to launch the code in background coroutine.
References: