本文介紹了java io ioexception 無法解析來自服務器地理編碼器的響應的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用此代碼獲取地理地址:
I am using this code to get geographical addresses:
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";
}
之前我得到一個地址列表返回,但現在我每次都得到這個異常:
Earlier I was getting an address list returned, but now I get, every time, this exception:
java.io.IOException unable to parse response from server
請幫忙.
推薦答案
終于解決了我的問題.
如果您嘗試非常頻繁地(一分鐘內多次)訪問服務器以從 lat,long 獲取地址,那么您可能會遇到此異常.此問題的解決方案可以是:
If you try to hit server very frequently(several times in a minute) for getting address from lat,long then you can get this exception.The solutions of this problem can be:
1-請盡量避免在一分鐘內多次點擊地址.
2-在不同的設備上運行此代碼.
如果您想在同一設備上運行此代碼,請清除您的應用數據(或卸載您的應用)并等待一段時間.
If you want to run this code on same device then clear your app data(or uninstall your app) and wait for some time.
這篇關于java io ioexception 無法解析來自服務器地理編碼器的響應的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!