Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

English instead of local language for Geocoder

I am using Geocoder to get address from lan/lat coordinates. The problem is that the address is in local language (the street name usually). How can I set it to be only in English?

I am using:

Geocoder geocoder = new Geocoder(Context, Locale.getDefault());

Tried:

Geocoder geocoder = new Geocoder(Context, Locale.ENGLISH);
Geocoder geocoder = new Geocoder(Context, Locale.US);

With no luck.

like image 276
Dim Avatar asked Feb 11 '14 21:02

Dim


2 Answers

API 19
The answer is not completely correct I think.
I have just had that case, when I set the GeoCoder locale to English then I get wrong street names.
It does not translate them but it removed language specific parts, that's a concern for me.

"Straße" became "St" for example.

The Google Maps HTTP Geocoder API is different in this regard, when I set an english language the streets are returned correctly just the tested country was translated (Austria instead of Österreich).

As many people use the HTTP API as fallback in case the Geocoder fails this can be a problem, like in my case.
My solution is to always use the locale of the country for BOTH APIs, then the results match.
The HTTP API has a &language parameter which understands Local.toString() as value;
The Geocoder can be initlized like in the original question shown.

like image 137
John Avatar answered Nov 08 '22 11:11

John


create a new locate instance like this:

    Locale aLocale = new Builder().setLanguage("en").setScript("Latn").setRegion("RS").build();
    Geocoder geocoder = new Geocoder(context,aLocale);

https://developer.android.com/reference/java/util/Locale.Builder.html

like image 37
HoangYell Avatar answered Nov 08 '22 12:11

HoangYell