2014-12-23 69 views
0
 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,表示「超時等待服務器響應」 ,當我嘗試使用單獨的線程處理代碼時,由於IOException異常,有時設備會凍結。

我應該怎麼做以避免異常?

plz幫助...

+0

可能是您的Internet連接速度緩慢... –

+0

我也在Geocoding和Reverse Geocoding中都面臨此問題..超過50%的時間請求是TIME OUT .. –

回答