Android Studio Geocoder RPC失败,状态为102

时间:2018-03-29 10:15:43

标签: android android-maps geocoder

处理从数据库获取地址的项目。

从这些地址我得到LatLng并将它们固定在谷歌地图活动上。

我使用此方法从地址获取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类有错误,遗漏了一些方法:

enter image description here

会重新安装Android Studio吗?

2 个答案:

答案 0 :(得分:0)

此问题已在https://stackoverflow.com/a/46256093/20394

中解决

解决方案是将Google Play服务升级到修订版44 +

答案 1 :(得分:0)

似乎模拟器没有互联网连接。从以太网改为WiFi解决了这个问题。在以太网上,DNS是域名,因此出于某种原因无法连接到Internet。