java io ioexception unable to parse response from server geocoder(java io ioexception 无法解析来自服务器地理编码器的响应)
问题描述
我正在使用此代码获取地理地址:
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 
请帮忙.
推荐答案
终于解决了我的问题.
如果您尝试非常频繁地(一分钟内多次)访问服务器以从 lat,long 获取地址,那么您可能会遇到此异常.此问题的解决方案可以是:
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-在不同的设备上运行此代码.
如果您想在同一设备上运行此代码,请清除您的应用数据(或卸载您的应用)并等待一段时间.
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 无法解析来自服务器地理编码器的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java io ioexception 无法解析来自服务器地理编码器的响应
				
        
 
            
        基础教程推荐
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
 - 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
 - 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
 - Java 实例变量在两个语句中声明和初始化 2022-01-01
 - 多个组件的复杂布局 2022-01-01
 - Java Swing计时器未清除 2022-01-01
 - 大摇大摆的枚举 2022-01-01
 - 不推荐使用 Api 注释的描述 2022-01-01
 - 验证是否调用了所有 getter 方法 2022-01-01
 - 从 python 访问 JVM 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				