Android 4.1 Geocoder.getLocationFromName() throws IOException: Unable to parse response from server ONLY over 3G

ε祈祈猫儿з 提交于 2019-12-11 05:52:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!