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
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();
}
}
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.
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.
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
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.
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());