11

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.

Atul Bhardwaj
  • 6,647
  • 5
  • 45
  • 63
  • ... So there are two possibilites: 1: The network state changed and you are not getting a response from the server. Or, 2: You changed something that broke your code. Why don't you go back and make sure you didn't change anything from the time it was working until now. If all is good, make sure you can actually reach the server on the network though other means. If you are still having problems, show us your code and the Logcat (= – dcow May 17 '12 at 18:24
  • The previous and current code is 100% same – Atul Bhardwaj May 17 '12 at 18:33
  • So did you do the other things I suggested? – dcow May 17 '12 at 18:37
  • @David I did all the things you suggested.But not working – Atul Bhardwaj May 17 '12 at 18:40
  • 1
    So if you didn't change anything, then it would make sense that you're getting bad data from the server, no? The only suggestion I have other than to wait and try later is to clear your app's data or uninstall and reinstall the app incase the cache contains a bad, or corrupt, response. – dcow May 17 '12 at 18:44
  • Nothing is working in my case. – Atul Bhardwaj May 18 '12 at 05:24
  • 1
    I have the same issue, and fix in this answer -> http://stackoverflow.com/a/19170557/2621050 – Bruno Pinto Oct 03 '13 at 23:02

5 Answers5

6

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.

Atul Bhardwaj
  • 6,647
  • 5
  • 45
  • 63
  • I have tested this in two devices motorola and samsung. For Motorola i am able to get the data but for samsung device still i am unable to fix it. Did you get any other way to fix this. – Anchal Nov 23 '12 at 10:33
  • @Atul Bhardwaj : I am too facing the same issue, still trying to resolve but no luck. – Nandagopal T Apr 05 '13 at 06:15
  • As John mentioned, its working fine on some devices not on few devices.After sometime/ reboot of the device makes the same functionality to work on the devices that were not been before.Looks very strange!. Do anybody get any way to fix this ? – Nandagopal T Apr 05 '13 at 06:20
2

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.

Tadas Valaitis
  • 870
  • 10
  • 11
0

My solution was:

Settings > Date & Time > Automatic date & time (Use network-provided time)
uranpro
  • 85
  • 1
  • 7
0

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" />
iko_wp
  • 739
  • 6
  • 9
0

I was getting the same problem. i added this permission

android.permission.WRITE_EXTERNAL_STORAGE

and it worked well.

user1859771
  • 186
  • 3
  • 14