从事从数据库获取地址的项目。
从这些地址中,我得到了 LatLng 并将它们固定在 Google 地图活动中。
我使用这种方法从地址获取 LatLng :
public LatLng getLocationFromAddress(Context context, String inputtedAddress) {
Geocoder coder = new Geocoder(context);
List<Address> address;
LatLng resLatLng = null;
try {
// May throw an IOException
address = coder.getFromLocationName(inputtedAddress, 5);
if (address == null) {
return null;
}
if (address.size() == 0) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
resLatLng = new LatLng(location.getLatitude(), location.getLongitude());
} catch (IOException ex) {
ex.printStackTrace();
}
return resLatLng;
直到 2 天前,它给了我来自 285 个地址的 164 个正确坐标。某些地址出于某种原因将 LatLng 设为 null。
在不更改任何代码的情况下,现在我在对地理编码器的前 8-10 次调用中收到以下错误:
W/System.err: java.io.IOException: Timed out waiting for response from server
W/System.err: at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
之后,其余的给出这个错误:
W/System.err: java.io.IOException: RPC failed with status 102
at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
给出错误的确切行是:
address = coder.getFromLocationName(inputtedAddress, 5);
编辑:
经过更多调查后,我发现 Geocoder.java 类有错误,缺少一些方法:
重新安装 Android Studio 可以吗?