问题
I've been developing and Android App that uses Google's geocoder to translate different latitudes and longitudes to human readable addresses but just a few minutes ago I've been getting an IOException with the following message "Timed out waiting for response from server". Is anyone else facing the same problem? I know that in January of this year, a similar issue occured with the geocoder API and was a Google's issue.
I haven't changed anything related to the use of the geocoder in the application for months now.
I use the geocoder as expected:
Geocoder geocoder = new Geocoder(this, Locale.getDefault()); List addresses = geocoder.getFromLocation(latitude, longitude, 1);
And I have the correct permissions in my manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Here's the full stacktrace that I get:
04-03 22:55:51.788 19955-19955/com.tek3.thanksfrog W/System.err: java.io.IOException: Timed out waiting for response from server
04-03 22:55:51.798 19955-19955/com.tek3.thanksfrog W/System.err: at android.location.Geocoder.getFromLocation(Geocoder.java:136)
04-03 22:55:51.798 19955-19955/com.tek3.thanksfrog W/System.err: at com.tek3.thanksfrong.AppController.getLocationInfoFromLatLng(AppController.java:687)
04-03 22:55:51.798 19955-19955/com.tek3.thanksfrog W/System.err: at com.tek3.thanksfrong.fragments.NewSceneFragment.loadCurrentLocationAddress(NewSceneFragment.java:268)
04-03 22:55:51.808 19955-19955/com.tek3.thanksfrog W/System.err: at com.tek3.thanksfrong.fragments.NewSceneFragment.onResume(NewSceneFragment.java:247)
04-03 22:55:51.808 19955-19955/com.tek3.thanksfrog W/System.err: at android.support.v4.app.Fragment.performResume(Fragment.java:1832)
04-03 22:55:51.808 19955-19955/com.tek3.thanksfrog W/System.err: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
04-03 22:55:51.808 19955-19955/com.tek3.thanksfrog W/System.err: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
04-03 22:55:51.818 19955-19955/com.tek3.thanksfrog W/System.err: at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
04-03 22:55:51.818 19955-19955/com.tek3.thanksfrog W/System.err: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
04-03 22:55:51.818 19955-19955/com.tek3.thanksfrog W/System.err: at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
04-03 22:55:51.818 19955-19955/com.tek3.thanksfrog W/System.err: at android.os.Handler.handleCallback(Handler.java:725)
04-03 22:55:51.818 19955-19955/com.tek3.thanksfrog W/System.err: at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 22:55:51.818 19955-19955/com.tek3.thanksfrog W/System.err: at android.os.Looper.loop(Looper.java:176)
04-03 22:55:51.818 19955-19955/com.tek3.thanksfrog W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5317)
04-03 22:55:51.828 19955-19955/com.tek3.thanksfrog W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
04-03 22:55:51.828 19955-19955/com.tek3.thanksfrog W/System.err: at java.lang.reflect.Method.invoke(Method.java:511)
04-03 22:55:51.828 19955-19955/com.tek3.thanksfrog W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
04-03 22:55:51.828 19955-19955/com.tek3.thanksfrog W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
04-03 22:55:51.828 19955-19955/com.tek3.thanksfrog W/System.err: at dalvik.system.NativeStart.main(Native Method)
回答1:
First of all, it depends on which version of Android you are working. For example in the API 23, you need to check the permission for having the right to use the location permission?
My second point is : do you check if your position (latitude and longitude) are not null. Because if you use a location manager sometimes the position is null, because the GPS is slower than the Network or because the network and the GPS is not available.
But I am not sure about my last point, but for using geocoder from Google don't you need to have an API key? Or maybe I just mixed everything
来源:https://stackoverflow.com/questions/36390726/ioexception-when-using-gocoder-timed-out-waiting-for-response-from-server