我正在使用小型library对某个位置进行反向地理编码。 我的问题是我的UI中的位置名称(我使用反向地理编码设置的TextView,如“Aberdeen,United Kingdom”的位置名称)与手机的默认语言(如保加利亚语)相同(如果手机语言是保加利亚语,我的应用程序中的其他所有内容都是英文。
所以我正在寻找一种方法如何将Locale.ENGLISH(或类似的东西)设置为我用于获取位置名称的以下方法:
Observable<List<Address>> reverseGeocodeObservable;
String locationName = "";
....
public void getLocationName(){
reverseGeocodeObservable
.subscribeOn(Schedulers.io())// use I/O thread to query for addresses
.observeOn(AndroidSchedulers.mainThread())// return result in main android thread to manipulate UI
.subscribe(new Subscriber<List<Address>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
Log.d(TAG,"OnError Geocode");
locationName = sharedPref.getString(getString(R.string.location_name_on_error),"unknown");
}
@Override
public void onNext(List<Address> addresses) {
if(addresses.size() > 0) {
Address address = addresses.get(0);
Log.v(MainActivity.class.getSimpleName(),"Locality: "+address.getLocality() + ", CountryName " + address.getCountryName());
//check if cityName is null...
String cityName = "unknown";
if(address.getLocality() != null) {
cityName = address.getLocality();
//if it is, try to get the subAdmin Area instead...
}else if (address.getSubAdminArea() != null){
cityName = address.getSubAdminArea();
}
String countryName = address.getCountryName();
editor.putString(getString(R.string.location_name_on_error),cityName + ", " + countryName);
editor.apply();
locationName = getString(R.string.location_name, cityName, countryName);
}
}
});
}
答案 0 :(得分:1)
您图书馆的ReverseGeocodeObservable
使用Geocoder
获取地址,但它使用不带语言环境的地理编码器。尝试编译您自己的此库版本并添加Locale属性,请参阅public Geocoder (Context context, Locale locale)