【发布时间】:2012-05-25 08:41:12
【问题描述】:
我正在使用此代码获取地理地址:
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:您更改了破坏代码的内容。你为什么不回去确保从它工作到现在你没有改变任何东西。如果一切正常,请确保您可以通过其他方式实际访问网络上的服务器。如果您仍然遇到问题,请向我们展示您的代码和 Logcat (=
-
之前和现在的代码100%相同
-
那么你做了我建议的其他事情吗?
-
因此,如果您没有更改任何内容,那么您从服务器获取错误数据是有道理的,不是吗?除了等待稍后再试之外,我唯一的建议是清除应用程序的数据或卸载并重新安装应用程序,以防缓存包含错误或损坏的响应。
-
我有同样的问题,并在这个答案中修复 -> stackoverflow.com/a/19170557/2621050
标签: java android geolocation gps locationlistener