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

后端 未结 7 686
醉酒成梦
醉酒成梦 2021-01-12 20:41

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 t

相关标签:
7条回答
  • 2021-01-12 21:17

    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();
     }
    }
    
    0 讨论(0)
  • 2021-01-12 21:25

    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.

    0 讨论(0)
  • 2021-01-12 21:28

    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.

    0 讨论(0)
  • 2021-01-12 21:30

    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
    
    0 讨论(0)
  • 2021-01-12 21:31

    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.

    0 讨论(0)
  • 2021-01-12 21:41

    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());
    
    0 讨论(0)
提交回复
热议问题