簡體   English   中英

java io ioexception無法解析服務器地理編碼器的響應

[英]java io ioexception unable to parse response from server geocoder

我使用此代碼獲取地理地址:

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";
}

早些時候我收到了一個地址列表,但現在我每次都得到這個例外:

java.io.IOException unable to parse response from server 

請幫忙。

最后我得到了解決問題的方法。

如果你試圖非常頻繁地命中服務器(一分鍾幾次)從lat獲取地址,那么你可以得到這個例外。這個問題的解決方案可以是:

1 - 請盡量避免在一分鍾內收到幾次點擊。
2 - 在不同設備上運行此代碼。

如果您想在同一設備上運行此代碼,請清除您的應用數據(或卸載您的應用)並等待一段時間。

我的三星Galaxy Tab 10.1遇到了同樣的問題。 我搜索時間尋找解決方案並沒有任何幫助。 要解決問題請嘗試以下操作

轉到位置設置並啟用:

1.使用無線網絡2.使用GPS衛星

等待GPS定位

在此之后,地理編碼服務器響應。 即使我禁用無線和GPS位置,服務器也正常工作。 我認為只有在您與Google分享您的位置時才能使用地理編碼器。

我的解決方案是:

Settings > Date & Time > Automatic date & time (Use network-provided time)

我的問題的原因是沒有對地理編碼器的適當權限

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

我遇到了同樣的問題。 我添加了這個權限

android.permission.WRITE_EXTERNAL_STORAGE

它運作良好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM