java.io.IOException: Unable to parse response from server at getFromLocationName()
Asked Answered
R

7

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)...

Roadway answered 31/10, 2011 at 10:38 Comment(11)
what is saveas here an Edittext?Stanislaw
yes ,it is an EditText..Roadway
Have you tried debugging this in Eclipse or put a log on newAddress to know what the variable contains ?Windle
and what you are entering in it Lat/Long or any address? BTW this happens when there are no results matching the address you enteredStanislaw
@saurabh: city name like mumbai ,nagpurRoadway
@Windle : yes ..it contains ,what i enter in the Edittext like city nameRoadway
@Stanislaw : but i m not entering the garbage value , it should work ,at-least when i am trying to show the cityRoadway
List<Address> addresses = geocoder.getFromLocationName("New York", 1); try this, and let me know what will you get.Egest
@Egest :ERROR/MapActivity(1278): Couldn't get connection factory client and in the catch block "java.io.IOException: Unable to parse response from server "Roadway
and what about this? Geocoder geocoder = new Geocoder(MapPage.this, Locale.ENGLISH); List<Address> returnedaddresses = geocoder .getFromLocationName("New York", 1); so just for try change Locale.getDefault() to Locale.ENGLISH? and what happen let me know?Egest
@Nibha try solution on this link #3575144Stanislaw
D
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.

Djokjakarta answered 16/3, 2012 at 10:47 Comment(0)
I
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.

Impious answered 15/10, 2012 at 9:59 Comment(0)
E
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());
Ecclesiastes answered 3/10, 2013 at 23:0 Comment(0)
R
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.

Robertoroberts answered 5/11, 2011 at 15:2 Comment(0)
S
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();
 }
}
Stanislaw answered 31/10, 2011 at 12:6 Comment(0)
C
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
Convolve answered 1/5, 2013 at 22:16 Comment(0)
C
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.

Culottes answered 24/1, 2014 at 0:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.