【问题标题】:Geocoder "Timed out waiting for response from server"地理编码器“等待服务器响应超时”
【发布时间】:2022-02-15 20:05:20
【问题描述】:

我正在尝试将纬度和经度转换为地址。当我使用WIFI时,我得到了正确的答案。但是当我尝试使用 3G/LTE 时,我得到了错误:

等待服务器响应超时。

我在调试模式下发现了这一点。但为什么?我正在使用相同的信息(纬度,经度)。我该如何解决?这是我的功能

public void convert_adresses (double lat , double lng) throws IOException
{
    addresses = geocoder.getFromLocation(lat, lng, 1);


    address = addresses.get(0).getAddressLine(0);
    city = addresses.get(0).getAddressLine(1);
    country = addresses.get(0).getAddressLine(2);

    txt_street.setText(address);
    txt_city.setText(city);
    txt_country.setText(country);

}

我这样称呼它:

try {
            convert_adresses(latitude,longtitude);
        } catch (IOException e) {
            e.printStackTrace();
}

有人有想法吗?

【问题讨论】:

标签: java android


【解决方案1】:

我不确定 GEOcoding.. 可能是您的网络提供商的问题...

尝试从设备打开以下 URL 并检查您是否通过 wifi 连接获得所需的输出

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA

【讨论】:

  • 我得到相同的输出:/
  • 也没有不同
  • 我的问题在于网络提供商,我尝试了不同的 wifi。它奏效了。
【解决方案2】:

new Geocoder(context) -> 你必须给上下文的参数一个活动或使用活动的基类。不要使用 Context 类实例。

【讨论】:

    【解决方案3】:

    我不知道如何,但这解决了问题 addresses = geocoder.getFromLocation(lat, lng, 2);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-20
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 2020-12-30
      • 2018-12-10
      • 1970-01-01
      相关资源
      最近更新 更多