Android: Nexus One - Geocoder causes IOException - works perfectly with other devices and emulator
Asked Answered
W

2

6

The code below works perfectly for real devices running on 1.5, 1.6 and 2.0 as well as the emulator running on 2.1.

However, executing it on the Nexus One (running 2.1) raises an IOException:

java.io.IOException: Unable to parse response from server
at android.location.Geocoder.getFromLocation(Geocoder.java:124)

That's the code snippet where it happens:

Double myLatitude = AppObject.myLocation.getLatitude();
Double myLongitude = AppObject.myLocation.getLongitude();
DEBUG.i(TAG, "My location: " + myLatitude + " | " + myLongitude);
Geocoder geocoder = new Geocoder(MainActivity.this);
java.util.List<Address> addressList;
try {
    addressList = geocoder.getFromLocation(myLatitude, myLongitude, 5);
    if(addressList!=null && addressList.size()>0) {
        currentAddress = new String();
        DEBUG.i(TAG,addressList.get(0).toString());
        currentAddress = addressList.get(0).getAddressLine(0) + ", "
        + addressList.get(0).getAddressLine(1) + ", "
        + addressList.get(0).getAddressLine(2); 

    }
    return true;

} catch (IOException e) {
    e.printStackTrace();
    return false;
}
Worse answered 18/1, 2010 at 16:23 Comment(5)
I've got almost exactly the same code in an app that I've written, and it runs fine on my Nexus One. Are you able to narrow it down to anything specific, like maybe the Nexus One has no internet connection when you call the geocoder?Livi
Do you have <uses-permission android:name="android.permission.LOCATION" /> in your manifest?Indic
It somehow works now. Without any changes on my code nor on the Nexus One. Spooky. haseman: I'm using ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION, but I couldn't find the by you recommended android.permission.LOCATION in the documentation: developer.android.com/intl/fr/reference/android/…Worse
Just because I came across this later... I am sure this is a server-side issue because code which I've released onto the Market and worked fine all through testing has had this happen (very occasionally).Charmer
Damn i have this same problem :T the simulator is connected to the internets yet it throws an IOException. FFUU.Veradia
D
1

Hi I fell into the same problem and same situation. I got a Nexus One and I got a workaround to make addressList = geocoder.getFromLocation(myLatitude, myLongitude, 1); work. You just have to restart your device. What I noticed is that Geocoder's getFromLocation method isn't aware of any change in Locale settings (in my case, what made the method stop working was the change of my default Locale). After a restart everything worked. Anyone got a reasonably reason for this? (Sorry for the word game :-P )

Densimeter answered 22/8, 2011 at 20:22 Comment(0)
B
0

I'm using a HTC Tmobile G2, and I had the same problem while testing a GeoCoder based feature. A reboot helped, but that's not an acceptable solution when my customers start complaining about this. If this is some kind of cache clearing issue, then I hope a workaround can be put in place programmatically.

Butene answered 3/11, 2011 at 23:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.