我正在使用一个小库对一个位置进行反向地理编码。我的问题是,我的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);
}
}
});
}
库中的ReverseGeocodeObservable
使用Geocoder
来获取地址,但它使用不带Locale的Geocoder。尝试编译您自己版本的此库并添加Locale属性,请参阅public Geocoder (Context context, Locale locale)