繁体   English   中英

java io ioexception无法解析服务器地理编码器的响应

[英]java io ioexception unable to parse response from server geocoder

我使用此代码获取地理地址:

private String getAddress(Location location)
{
    try{
        List<Address>   addresses = new Geocoder(this,Locale.getDefault()).getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        if(addresses!=null)
        {
            String address="Address not available";

            for(int i=0;i<addresses.size();i++) 
            {

                Address addre=addresses.get(i);

                String street=addre.getAddressLine(0);
                if(null==street)
                    street="";

                String city=addre.getLocality();
                if(city==null) city="";

                String state=addre.getAdminArea();
                if(state==null) state="";


                String country=addre.getCountryName();
                if(country==null) country="";

                address=street+", "+city+", "+state+", "+country;

            }
            return address;
        }

    }
    catch (Exception e) {
        return "Address not available";
    }
    return "Address not available";
}

早些时候我收到了一个地址列表,但现在我每次都得到这个例外:

java.io.IOException unable to parse response from server 

请帮忙。

最后我得到了解决问题的方法。

如果你试图非常频繁地命中服务器(一分钟几次)从lat获取地址,那么你可以得到这个例外。这个问题的解决方案可以是:

1 - 请尽量避免在一分钟内收到几次点击。
2 - 在不同设备上运行此代码。

如果您想在同一设备上运行此代码,请清除您的应用数据(或卸载您的应用)并等待一段时间。

我的三星Galaxy Tab 10.1遇到了同样的问题。 我搜索时间寻找解决方案并没有任何帮助。 要解决问题请尝试以下操作

转到位置设置并启用:

1.使用无线网络2.使用GPS卫星

等待GPS定位

在此之后,地理编码服务器响应。 即使我禁用无线和GPS位置,服务器也正常工作。 我认为只有在您与Google分享您的位置时才能使用地理编码器。

我的解决方案是:

Settings > Date & Time > Automatic date & time (Use network-provided time)

我的问题的原因是没有对地理编码器的适当权限

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

我遇到了同样的问题。 我添加了这个权限

android.permission.WRITE_EXTERNAL_STORAGE

它运作良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM