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,它表示&#34;等待服务器的响应超时#34; 当我尝试使用单独的线程来处理代码时, 由于IOException,设备有时会冻结。
我应该怎么做以避免异常?
Plz帮助...