Why Geocoder Locale.US return address in Arabic in Dubai

140 Views Asked by At
Geocoder geocoder = new Geocoder(this, Locale.US);

The above code returns the address in English irrespective of device language. But in Dubai, the above code is not working and returns the address in Arabic.

How I get the address in English in Dubai using Geocoder?

1

There are 1 best solutions below

0
János Sicz-Mesziár On

What if you tricked the Context that you pass to the GeoCoder?

For example, by changing the context locale like in the following Kotlin code:

val configuration = Configuration(resources.configuration)
configuration.setLocale(Locale.ENGLISH)
val newContext = createConfigurationContext(configuration)
val geocoder = Geocoder(newContext, Locale.getDefault())

I haven't tried it, just an idea that came to mind. My guess is the GeoCoder uses the passed Context to detect the preferred locale.