【发布时间】:2018-03-18 10:01:03
【问题描述】:
我正在使用 goecoder 尝试将地址转换为 lat/lng。但是,地理编码器似乎适用于某些地址,但不适用于其他地址。如果我在谷歌地图上搜索地址,它会完美定位。
这是一个示例 38 Crichton Street, Ottawa, ON, Canada 当我运行下面的代码时,这个地址返回 0 个结果
Location loc = null;
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> address = geoCoder.getFromLocationName(addr, 1);
if (address.size() == 0) {
return null;
}
double latitude = address.get(0).getLatitude();
double longitude = address.get(0).getLongitude();
loc = new Location("Unknown");
loc.setLatitude(latitude);
loc.setLongitude(longitude);
} catch (IOException ioException) {
Log.e(TAG, ioException.toString());
} catch (IllegalArgumentException illegalArgumentException) {
Log.e(TAG, illegalArgumentException.toString());
}
知道为什么或如何解决它
谢谢
【问题讨论】:
标签: android google-geocoder google-geocoding-api