11

我正在使用此代码获取地理地址:

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 

请帮忙。

4

5 回答 5

6

最后我得到了我的问题的解决方案。

如果您尝试非常频繁地(一分钟内多次)访问服务器以从 lat,long 获取地址,那么您可能会遇到此异常。此问题的解决方案可以是:

1-请尽量避免在一分钟内多次点击地址。
2-在不同的设备上运行此代码。

如果您想在同一设备上运行此代码,请清除您的应用数据(或卸载您的应用)并等待一段时间。

于 2012-08-13T06:01:32.813 回答
2

我的三星 Galaxy Tab 10.1 也有同样的问题。我在几个小时内寻找解决方案,但没有任何帮助。要解决问题,请尝试以下操作:

转到位置设置并启用:

1.使用无线网络 2.使用 GPS 卫星

等待 GPS 定位修复

此后,地理编码器服务器响应。即使我禁用了无线和 GPS 定位,服务器仍在工作。我认为只有在您与 Google 共享您的位置时才能使用地理编码器。

于 2012-10-15T09:41:11.987 回答
0

我的解决方案是:

Settings > Date & Time > Automatic date & time (Use network-provided time)
于 2013-01-21T08:48:47.467 回答
0

我的问题原因是没有地理编码器的适当权限

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
于 2013-03-20T15:59:20.893 回答
0

我遇到了同样的问题。我添加了这个权限

android.permission.WRITE_EXTERNAL_STORAGE

它运作良好。

于 2014-02-17T10:32:01.083 回答