地理编码器区域设置语言总是 return 英语
Geocoder locale language always return english
我尝试根据当前位置使用特定语言获取城市,我之前像下面那样这样做并且一切正常但在我的新项目中它不起作用!
Geocoder geo = new Geocoder(getApplicationContext(), new Locale("ja"));
List<Address> addresses = null;
try {
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.size() > 0) {
Log.d("CITY",addresses.get(0).getLocality());
city.setText(addresses.get(0).getLocality());
} else {
// do your stuff
}
} catch (IOException e) {
e.printStackTrace();
}
不管设置哪种语言总是城市名称 return 用英语!
经过一些研究,我明白必须设置 geo.getFromLocation maxResults > 1
因为总是第一个地址 returned 在列表中, return 用英语,但下一个项目将是您的特定语言,所以只是需要改变
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
到
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 2);
和 getLocality 这样 addresses.get(1).getLocality()
我尝试根据当前位置使用特定语言获取城市,我之前像下面那样这样做并且一切正常但在我的新项目中它不起作用!
Geocoder geo = new Geocoder(getApplicationContext(), new Locale("ja"));
List<Address> addresses = null;
try {
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.size() > 0) {
Log.d("CITY",addresses.get(0).getLocality());
city.setText(addresses.get(0).getLocality());
} else {
// do your stuff
}
} catch (IOException e) {
e.printStackTrace();
}
不管设置哪种语言总是城市名称 return 用英语!
经过一些研究,我明白必须设置 geo.getFromLocation maxResults > 1
因为总是第一个地址 returned 在列表中, return 用英语,但下一个项目将是您的特定语言,所以只是需要改变
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
到
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 2);
和 getLocality 这样 addresses.get(1).getLocality()