【发布时间】:2014-12-23 09:31:56
【问题描述】:
Geocoder geocode = new Geocoder(MainPage.this);
List<Address> address = null;
StringBuilder addressText = null;
try {
address = geocode.getFromLocation(latitudeTemp, longitudeTemp,
1);
} catch (IOException e) {
e.printStackTrace();
}
if (address != null && address.size() != 0) {
Address addr = address.get(0);
addressText = new StringBuilder();
if (addr.getCountryName() != null)
addressText.append(addr.getCountryName()).append(" ");
if (addr.getAdminArea() != null)
addressText.append(addr.getAdminArea()).append(" ");
if (addr.getLocality() != null)
addressText.append(addr.getLocality()).append(" ");
if (addr.getSubLocality() != null)
addressText.append(addr.getSubLocality()).append(" ");
if (addr.getThoroughfare() != null)
addressText.append(addr.getThoroughfare()).append(" ");
if (addr.getFeatureName() != null)
addressText.append(addr.getFeatureName()).append(" ");
} else {
addressText = new StringBuilder()
.append("error");
}
myAddress2 = addressText;
我正在尝试使用反向地理编码来获取实际地址。 而且,实际上,上面的代码通常可以正常工作。
但是,有时它会给出 IOException,即“等待服务器响应超时” 当我尝试使用单独的线程来处理代码时, 由于 IOException,设备有时会冻结..
我应该怎么做才能避免异常?
请帮忙...
【问题讨论】:
-
可能是因为您的 Internet 连接速度慢...
-
我在地理编码和反向地理编码中也遇到过这个问题。超过 50% 的请求超时。
标签: java android geocoding reverse-geocoding request-timed-out