我下面的代码没有给出任何结果。
list_addr = gc.getFromLocation(latitude, longitude, 5);
甚至不返回null
值...
它表现得像哑巴。
给我解决方案。
Geocoder.getFromLocations(double, double, int)
要么返回结果(即使 null 也是结果)或抛出异常。
您是否在代码中的某处默默地捕捉通用异常?
更新:
使用此代码,然后检查 logcat。它应该给你一个为什么这不起作用的原因:
Geocoder gc = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> list_addr = gc.getFromLocation(40.0d, 10.0d, 5);
} catch (IllegalArgumentException iae) {
Log.e("Geocoder IllegalArgumentException exception: ", iae.getMessage());
} catch (IOException ioe) {
Log.e("Geocoder IOException exception: ", ioe.getMessage());
}
更新2:
这原来是 Emulator v2.2: Android 中的一个错误;地理编码器,为什么我得到“服务不可用”?
试试这个
List<Address> addresses = new Geocoder(MyActivity.this,Locale.getDefault()).getFromLocation(latitude, longitude, 1);