6

I know the question has been asked frequently before ,but i am unable to get the solution from any answer or search results. I have to solve this issue ASAP .. I am trying to get the latitude and the longitude from the address enter by the user but i am continue getting :

java.io.IOException: Unable to parse response from server 

I am using this code :

        Geocoder geocoder = new Geocoder(this ,Locale.getDefault());
        String newAddress = (String)saveas.getText().toString();
        List<Address> addresses = geocoder.getFromLocationName(newAddress, 1);

I tried a lot with different possible ways but nothing works... The default map application works well, when the user enter the address it shows sucessfully that address in the map..How can i do the same..?

I have added all the required permissions and i am testing it on the real device(version 2.3)...

Nibha Jain
  • 7,742
  • 11
  • 47
  • 71
  • what is saveas here an Edittext? – ingsaurabh Oct 31 '11 at 10:48
  • yes ,it is an EditText.. – Nibha Jain Oct 31 '11 at 10:51
  • Have you tried debugging this in Eclipse or put a log on newAddress to know what the variable contains ? – Sephy Oct 31 '11 at 10:54
  • and what you are entering in it Lat/Long or any address? BTW this happens when there are no results matching the address you entered – ingsaurabh Oct 31 '11 at 10:55
  • @saurabh: city name like mumbai ,nagpur – Nibha Jain Oct 31 '11 at 10:59
  • @Sephy : yes ..it contains ,what i enter in the Edittext like city name – Nibha Jain Oct 31 '11 at 11:01
  • @ingsaurabh : but i m not entering the garbage value , it should work ,at-least when i am trying to show the city – Nibha Jain Oct 31 '11 at 11:06
  • List
    addresses = geocoder.getFromLocationName("New York", 1); try this, and let me know what will you get.
    – user370305 Oct 31 '11 at 11:09
  • @user370305 :ERROR/MapActivity(1278): Couldn't get connection factory client and in the catch block "java.io.IOException: Unable to parse response from server " – Nibha Jain Oct 31 '11 at 11:26
  • and what about this? Geocoder geocoder = new Geocoder(MapPage.this, Locale.ENGLISH); List
    returnedaddresses = geocoder .getFromLocationName("New York", 1); so just for try change Locale.getDefault() to Locale.ENGLISH? and what happen let me know?
    – user370305 Oct 31 '11 at 11:50
  • @Nibha try solution on this link http://stackoverflow.com/questions/3574644/how-can-i-find-latitude-and-longitude-using-address/3574792#3574792 – ingsaurabh Oct 31 '11 at 11:51

7 Answers7

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 starts responding. Even when I disabled wireless and GPS Location is server still working. I think geocoder only can be used if you share your location with Google.

Tadas Valaitis
  • 870
  • 10
  • 11
2

I solved the same issue changing the context.

I use Fragment, so my code is like this

    public class SearchRoteFragment extends Fragment{

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.teste_mapa, container, false);
        context = getActivity();
...
}

and when I call geocode I do this

Geocoder geoCoder = new Geocoder(context, Locale.getDefault());
Chirag Savsani
  • 6,020
  • 4
  • 38
  • 74
Bruno Pinto
  • 2,013
  • 3
  • 23
  • 33
2

Have you tried over a 3G connection? I've noticed that if you send several reverse geolocation requests from wifi, it looks like your IP is blocked after a while and the reverse geolocation won't respond for an amount of time. Switching to 3G made the request work for me when I had similar issues.

1

It may be useful if you set the locale parameter when creating Geocoder:

yourGeocoder = new Geocoder(this, Locale.CANADA); 

Please replace the second parameter with the best value.

I guess that the default locale value may be not corresponding the map region that you use.

flypen
  • 2,515
  • 4
  • 34
  • 51
0

Probably your phone is not connected and can't retrieve an answer from the server.

As explained here geocoder

throws IOException if the network is unavailable or any other I/O problem occurs
Community
  • 1
  • 1
h3r3b
  • 191
  • 2
  • 4
0

I was testing on Android 2.3.4, and received "Unable to parse response from server" exception.

Make sure your google map is working, mine was not working! Once google map started working Geocoder was fine.

I did toggled "Use wireless networks" & "Use GPS satellites" from "Location & security" settings.

Prakash
  • 4,479
  • 30
  • 42
0

I dont know if it helps BTW below is snippet from my project working fine modify it to suit your needs

String newAddress = saveas.getText().toString();
searchFromLocationName(newAddress);


private void searchFromLocationName(String name){
 try {
  List<Address> result
  = myGeocoder.getFromLocationName(name, MAX_RESULT);

  if ((result == null)||(result.isEmpty())){
   Toast.makeText(AndroidgetFromLocationNameActivity.this,
     "No matches were found or there is no backend service!",
     Toast.LENGTH_LONG).show();
  }else{

   MyArrayAdapter adapter = new MyArrayAdapter(this,
         android.R.layout.simple_list_item_1, result);
   listviewResult.setAdapter(adapter);

   Toast.makeText(AndroidgetFromLocationNameActivity.this,
     "Finished!",
     Toast.LENGTH_LONG).show();
  }


 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  Toast.makeText(AndroidgetFromLocationNameActivity.this,
    "The network is unavailable or any other I/O problem occurs!",
    Toast.LENGTH_LONG).show();
 }
}
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81