我尝试按照当前位置使用特定语言来获取城市我之前就像下面所做的一样,所有工作都很好,但在我的新项目中它不起作用!
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();
}
dos无论设置哪种语言总是用英语返回城市名称!
经过一些研究我明白必须设置geo.getFromLocation maxResults > 1
导致始终在列表中返回的第一个地址,用英语返回,但下一个项目将是您的特定语言,所以只需要更改
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
至
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 2);
和getLocality就像这个addresses.get(1).getLocality()