0

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

从这些地址中,我得到了 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 可以吗?

4

2 回答 2

0

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

于 2018-04-03T11:27:15.443 回答
0

此问题已在https://stackoverflow.com/a/46256093/20394中得到解决

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

于 2018-03-29T10:20:40.817 回答