问题
I am using the Geocoder in my android app to resolve a string in to Addresses. The following snippet of code works normally over Wifi, but not over 3G. When over 3G, it throws an IOException: Unable to parse response from server
.
In other discussions about this, a common answer is that a probable cause is that the Geocoder is used many times/minute, surpassing the threshold, and that causes the service to temporarily throw the exception. The I am sure this is not my case, because I never got the service to work on my new phone (Nexus S, android 4.1), which I got some weeks ago.
This is the snippet:
Geocoder gc = new Geocoder(this);
List<Address> newAddresses = gc.getFromLocationName(arg0.toString(), 10);
Any ideas?
回答1:
Instead of using that GeoCoder, use google's web api, you can make asynchronous api calls to that and get json objects with even more information than the android geocoder will ever give you.
it is better https://developers.google.com/maps/documentation/geocoding/
I've done this in several android apps and this also guarantees that you will get the same kind of results from crossplatform apps
来源:https://stackoverflow.com/questions/12714274/android-4-1-geocoder-getlocationfromname-throws-ioexception-unable-to-parse-r