Java的IO IOException异常无法解析来自服务器的地理codeR响应 [英] java io ioexception unable to parse response from server geocoder

查看:776
本文介绍了Java的IO IOException异常无法解析来自服务器的地理codeR响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这code获得地理地址:

I am using this code to get geographical addresses:

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";
}

我最早是在每次获得一个地址列表中返回,但现在我得到,此异常:

Earlier I was getting an address list returned, but now I get, every time, this exception:

java.io.IOException unable to parse response from server 

请帮忙。

推荐答案

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

Finally I got the solution of my problem.

如果您尝试打服务器非常频繁(多次在一分钟内)获取地址的经纬度,长那么你就可以得到这个问题的这一exception.The的解决方案可能是:

If you try to hit server very frequently(several times in a minute) for getting address from lat,long then you can get this exception.The solutions of this problem can be:

1,请尽量避免在一分钟内的点击数为地址。
2,运行在不同的设备本code。

1-Please try to avoid several hits for address in a minute.
2-Run this code on different device.

如果你想运行在同一台设备此code然后清除您的应用程序的数据(或卸载应用程序),并等待一段时间。

If you want to run this code on same device then clear your app data(or uninstall your app) and wait for some time.

这篇关于Java的IO IOException异常无法解析来自服务器的地理codeR响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆