Java 反向地理编码给出了IOException。。为什么总是超时? Geocoder geocode=新的Geocoder(MainPage.this); 列表地址=空; StringBuilder addressText=null; 试一试{ 地址=地理编码.getFromLocation(latitudeTemp,LongtudeTemp, 1); }捕获(IOE异常){ e、 printStackTrace(); } if(address!=null&&address.size()!=0){ 地址addr=Address.get(0); addressText=新的StringBuilder(); if(addr.getCountryName()!=null) addressText.append(addr.getCountryName()).append(“”); if(addr.getAdminArea()!=null) addressText.append(addr.getAdminArea()).append(“”); if(addr.getLocation()!=null) addressText.append(addr.getLocality()).append(“”); if(addr.getSubLocality()!=null) addressText.append(addr.getSubLocality()).append(“”); if(addr.getthoroughare()!=null) addressText.append(addr.getthoroughure()).append(“”); if(addr.getFeatureName()!=null) addressText.append(addr.getFeatureName()).append(“”); }否则{ addressText=新的StringBuilder() .附加(“错误”); } myAddress2=addressText;
我正在尝试使用反向地理编码来获取实际地址。 而且,实际上,上面的代码经常有效 然而,有时它会给出IOException,即“等待服务器响应超时” 当我尝试使用单独的线程来处理代码时, 由于IOException,设备有时会冻结 我应该做什么来避免异常Java 反向地理编码给出了IOException。。为什么总是超时? Geocoder geocode=新的Geocoder(MainPage.this); 列表地址=空; StringBuilder addressText=null; 试一试{ 地址=地理编码.getFromLocation(latitudeTemp,LongtudeTemp, 1); }捕获(IOE异常){ e、 printStackTrace(); } if(address!=null&&address.size()!=0){ 地址addr=Address.get(0); addressText=新的StringBuilder(); if(addr.getCountryName()!=null) addressText.append(addr.getCountryName()).append(“”); if(addr.getAdminArea()!=null) addressText.append(addr.getAdminArea()).append(“”); if(addr.getLocation()!=null) addressText.append(addr.getLocality()).append(“”); if(addr.getSubLocality()!=null) addressText.append(addr.getSubLocality()).append(“”); if(addr.getthoroughare()!=null) addressText.append(addr.getthoroughure()).append(“”); if(addr.getFeatureName()!=null) addressText.append(addr.getFeatureName()).append(“”); }否则{ addressText=新的StringBuilder() .附加(“错误”); } myAddress2=addressText;,java,android,geocoding,reverse-geocoding,request-timed-out,Java,Android,Geocoding,Reverse Geocoding,Request Timed Out,我正在尝试使用反向地理编码来获取实际地址。 而且,实际上,上面的代码经常有效 然而,有时它会给出IOException,即“等待服务器响应超时” 当我尝试使用单独的线程来处理代码时, 由于IOException,设备有时会冻结 我应该做什么来避免异常 Plz help…听起来像是网络或服务器问题超出了您的控制范围。您可以尝试()作为一种处理方法。可能是因为您的Internet连接速度慢…我也在地理编码和反向地理编码中遇到了这个问题。。超过50%的请求超时。。 Geocoder g
Plz help…听起来像是网络或服务器问题超出了您的控制范围。您可以尝试()作为一种处理方法。可能是因为您的Internet连接速度慢…我也在地理编码和反向地理编码中遇到了这个问题。。超过50%的请求超时。。
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;