Geocoder.getFromLocation grpc failed on Android real device

fargath picture fargath · Nov 16, 2017 · Viewed 27k times · Source

I need to get the city and state from latitude and longitude. Geocoder does this function to get the city and state. But I am getting an error java.io.IOException: grpc failed in below line only on Android real device. It is working fine in emulators.

new Geocoder(context).getFromLocation(latLng.latitude, latLng.longitude, 1).get(0);

Also I have been calling this function using Asynctask which is suggested in another post Geocoder grpc failed in stack overflow but nothing works for me.

And I have restart the device as well but still it is failing.

Help needed here. Thanks in advance.

Note: I tested in Google Pixel XL, Samsung S6 edge, Samsung S4.

Answer

xomena picture xomena · Nov 16, 2017

It looks like this is ongoing issue that was reported in the Google issue tracker both for real devices and emulators. You can refer to the following bugs:

https://issuetracker.google.com/issues/64418751

https://issuetracker.google.com/issues/64247769

Unfortunately, Google haven't solved these issues yet.

As a workaround you can consider using the Geocoding API web service. Please note that there is a Java client library for web services that you can find on Github:

https://github.com/googlemaps/google-maps-services-java

Using Java client library for web services you can implement reverse geocoding lookup that shouldn't give you the error that you experience with native Android geocoder.

The Javadoc for client library is located at

https://googlemaps.github.io/google-maps-services-java/v0.2.5/javadoc/

I hope this helps!