English instead of local language for Geocoder

北战南征 提交于 2019-12-09 00:36:25

问题


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.


回答1:


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.




回答2:


I don't think this is possible. Street names are street names. They don't get translated. You have a name. Your name is your name, no matter what language anybody may speak. You don't "translate" your name when you talk to people in foreign languages.

A Geocoder is just a database that maps Geocoordinates to other entitities. In general you won't find multiple names for a street. There are a few instances where names are translated (city names, for example, can be translated into multiple languages), but theese are the exception and not the rule.




回答3:


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



来源:https://stackoverflow.com/questions/21713507/english-instead-of-local-language-for-geocoder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!