问题
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)...
回答1:
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.
回答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.
回答3:
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());
回答4:
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.
回答5:
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();
}
}
回答6:
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
回答7:
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.
来源:https://stackoverflow.com/questions/7952550/java-io-ioexception-unable-to-parse-response-from-server-at-getfromlocationname