简体   繁体   中英

java io ioexception unable to parse response from server geocoder

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 

Please help.

Finally I got the solution of my problem.

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-Please try to avoid several hits for address in a minute.
2-Run this code on different device.

If you want to run this code on same device then clear your app data(or uninstall your app) and wait for some time.

I had the same problem with my Samsung Galaxy Tab 10.1. I search hours for a solution and nothing helped. To fix issues try following:

Go to Location settings and enable:

1.Use Wireless networks 2.Use GPS satellites

wait for GPS location fix

After this, geocoder server responded. Even when I disabled wireless and GPS Location, server was working. I think geocoder can only be used if you share your location with Google.

我的解决方案是:

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

My cause of the issue was not having the proper permissions for the geocoder

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

I was getting the same problem. i added this permission

android.permission.WRITE_EXTERNAL_STORAGE

and it worked well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM