我正在使用GeoCoder从lat和long中获取地址。这是我的代码:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addressList = geocoder.getFromLocation(lat, lng, 1);
它可以用英语给我正确的地址。我需要俄语的地址。到目前为止,我尝试过的是将语言环境设置为俄语,并将其传递给geocoder对象。
Locale aLocale = new Locale.Builder().setLanguage("RU").setScript("Latn").setRegion("RS").build();
Geocoder geocoder = new Geocoder(this, aLocale);
List<Address> addressList = geocoder.getFromLocation(lat, lng, 1);
但是我仍然用英语而不是俄语来获得地址。请建议我该怎么办。
提前致谢。
最佳答案
试试这个代码
Locale aLocale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
aLocale = new Locale.Builder().setLanguage("RU").setScript("Latn").setRegion("RS").build();
} else {
aLocale = new Locale("RU");
}
Geocoder geocoder = new Geocoder(this, aLocale);
List<Address> addressList = geocoder.getFromLocation(lat, lng, 1);
关于java - 使用Android Geocoder getFromLocation获取俄语的地址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51441328/