我正在使用此代码获取地理地址:
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,long 获取地址,那么您可能会遇到此异常。此问题的解决方案可以是:
1-请尽量避免一分钟内多次点击地址。
2-在不同的设备上运行此代码。
如果您想在同一台设备上运行此代码,请清除您的应用数据(或卸载您的应用)并等待一段时间。
关于java io ioexception 无法解析来自服务器地理编码器的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10641346/