When I use call getFromLocationName I get an IOException with description "grpc failed".
Code that's ran
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
try {
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> listAdresses = geocoder.getFromLocationName("London", 10);
Log.i("PlaceInfo", listAdresses.get(0).toString());
} catch (IOException e) {
e.printStackTrace();
}
}
Error the console outputs:
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: java.io.IOException: grpc failed
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at co.siqve.maplocationdemo.MapsActivity.onMapReady(MapsActivity.java:70)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at com.google.android.gms.maps.zzaj.zza(Unknown Source)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at com.google.android.gms.maps.internal.zzaq.onTransact(Unknown Source)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at android.os.Binder.transact(Binder.java:499)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at com.google.android.gms.maps.internal.aq.a(:com.google.android.gms.DynamiteModulesB:5)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at com.google.maps.api.android.lib6.impl.bb.run(:com.google.android.gms.DynamiteModulesB:5)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at android.os.Looper.loop(Looper.java:154)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6119)
07-10 12:01:38.782 13712-13712/co.siqve.maplocationdemo W/System.err: at java.lang.reflect.Method.invoke(Native Method)
07-10 12:01:38.782 13712-13712/co.siqve.maplocationdemo W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
07-10 12:01:38.782 13712-13712/co.siqve.maplocationdemo W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Android SDK Version (API Level): 25
Android Studio plugins are up to date.
Thanks in advance!
EDIT:
Problem seems to be fixed now, here is my solution.
I face this issue on Android 4.4.2 device several times. For me the solution is simply to restart the handset. No code update no Android studio uninstall.
UPDATE:
The problem seems to be solved now. I'm not sure if it the problem ever was on my end, so if you had this problem prior to this post, re-run your app and see if it works now.
If it still doesn't work, here is the stuff I did myself that "might" have made it work:
This was happening also on my Samsung S7 Edge phone with Oreo installed. It only happened when I had an airplane mode on (not always - means something might have been cached at some points). I didn't explore the guts of Geocoder but I assume it requires some sort connectivity to get the information (that would also explain why this is happening so often on emulators). For me the solution was to check the network connectivity status and call this only when
status != NETWORK_STATUS_NOT_CONNECTED
.For this you can implement a broadcast receiver, that will listen to any status changes on network.
Register receiver
Setup broadcast receiver to handle the broadcast
Today (2017-09-16) my Android Studio (2.3.3) got an update for Google Play services to revision 44. The issue was fixed afterwards. No code or setup changes from my side.
I finally got this to work by using the following configuration for version 25 SDK, Build Tools and API emulator.
Also using Google API version 11.0.2.
It works for me if introduce Geocoder as singleton for application rather than create it every time. Make sure to call Geocoder.getFromLocationName() from worker thread.
For example: