【问题标题】:Reverse Geocoding gives IOException.. why always timed out?反向地理编码给出 IOException.. 为什么总是超时?
【发布时间】:2014-12-23 09:31:56
【问题描述】:
        Geocoder geocode = new Geocoder(MainPage.this);
        List<Address> address = null;
        StringBuilder addressText = null;
        try {
            address = geocode.getFromLocation(latitudeTemp, longitudeTemp,
                    1);
        } catch (IOException e) {
            e.printStackTrace();

        }

        if (address != null && address.size() != 0) {
            Address addr = address.get(0);
            addressText = new StringBuilder();

            if (addr.getCountryName() != null)
                addressText.append(addr.getCountryName()).append(" ");

            if (addr.getAdminArea() != null)
                addressText.append(addr.getAdminArea()).append(" ");
            if (addr.getLocality() != null)
                addressText.append(addr.getLocality()).append(" ");
            if (addr.getSubLocality() != null)
                addressText.append(addr.getSubLocality()).append(" ");
            if (addr.getThoroughfare() != null)
                addressText.append(addr.getThoroughfare()).append(" ");
            if (addr.getFeatureName() != null)
                addressText.append(addr.getFeatureName()).append(" ");

        } else {

            addressText = new StringBuilder()
                    .append("error");
        }
        myAddress2 = addressText;

我正在尝试使用反向地理编码来获取实际地址。 而且,实际上,上面的代码通常可以正常工作。

但是,有时它会给出 IOException,即“等待服务器响应超时” 当我尝试使用单独的线程来处理代码时, 由于 IOException,设备有时会冻结..

我应该怎么做才能避免异常?

请帮忙...

【问题讨论】:

  • 可能是因为您的 Internet 连接速度慢...
  • 我在地理编码和反向地理编码中也遇到过这个问题。超过 50% 的请求超时。

标签: java android geocoding reverse-geocoding request-timed-out


【解决方案1】:

这听起来像是您无法控制的网络或服务器问题。你可以试试exponential backoff (example) 来处理它。

【讨论】:

    猜你喜欢
    • 2021-01-26
    • 1970-01-01
    • 2018-08-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    相关资源
    最近更新 更多