我正在使用以下代码来获取地理位置:
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
请帮忙。
终于我找到了解决问题的办法。
如果您尝试频繁(在一分钟内几次)访问服务器以获取经纬度的地址,则会出现此异常。此问题的解决方案可以是:
1-请尽快避免地址多次被点击。
2在其他设备上运行此代码。
如果要在同一设备上运行此代码,请清除您的应用数据(或卸载您的应用),然后等待一段时间。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句