Reputation: 1457
Last month of so geocoder has started to fail every time with "grpc failed" error and I can't seem to be able to solve it. I've looked at java.io.IOException: grpc failed but it didn't really solve the problem.
For exampel the code
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
addresses = geocoder.getFromLocation(lat, lng, 1); // Here if fails with "grpc failed"
I've had the same code for years, but it's just lately it has stopped working when I recompile the app and test on an emulator or real device.
If I compile against SDK 25, using build tool 25 it works on an emulator with SDK 25. But if I try on an emulator with SDK 24, 26 or any other SDK version, it will fail with "grpc failed". I've tried to create a new virtual device etc. but same problem.
I have no clue how to fix it and what the problem is.
Current setup: targetSDK/compileSDK 25, build tool 25.0.3, Android Studio 2.3.3, regular emulator. (I've tried other build tools and SDK versions, but problem still remains)
Any ideas?
Upvotes: 17
Views: 14391
Reputation: 19
I have solution for exception "java.io.ioexception grpc failed"
Code:
try {
Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault());
List addresses = geocoder.getFromLocation(latitude, longitude, 1);
List addresslist = addresses;
String address = addresslist.get(0).getAddressLine(0);
Log.d("add", address);
} catch (IOException e) {
e.printStackTrace();
}
Upvotes: 0
Reputation: 1
I was able to fix a similar problem by adding
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
to my manifest file
Upvotes: 0
Reputation: 31
Well, this might be too late and for someone else looking for answers, in my case it was internet problem. My internet connection was bad
Upvotes: 1
Reputation: 134
It's related to Google Play Service on virtual devices. Use API25 and version 7.1.1 for solution.
Here are examples;
When I try on Genymotion and Google Play Services is disabled on virtual device (Error: Service not Available):
10-07 07:13:30.023 3481-3481/com.unalfaruk.mapexample I/System.out: Your Location: 65.96992333333333 -18.540028333333332
10-07 07:13:30.023 3481-3481/com.unalfaruk.mapexample W/System.err: java.io.IOException: Service not Available
10-07 07:13:30.024 3481-3481/com.unalfaruk.mapexample W/System.err: at android.location.Geocoder.getFromLocation(Geocoder.java:136)
10-07 07:13:30.024 3481-3481/com.unalfaruk.mapexample W/System.err: at com.unalfaruk.mapexample.MapsActivity$1.onLocationChanged(MapsActivity.java:71)
10-07 07:13:30.024 3481-3481/com.unalfaruk.mapexample W/System.err: at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:297)
When I try on Genymotion and Google Play Services is enabled (Error: grpc failed):
10-07 07:18:56.325 2694-2694/com.unalfaruk.mapexample I/System.out: Your Location: 65.96669666666666 -15.0
10-07 07:18:57.670 2694-2694/com.unalfaruk.mapexample W/System.err: java.io.IOException: grpc failed
10-07 07:18:57.670 2694-2694/com.unalfaruk.mapexample W/System.err: at android.location.Geocoder.getFromLocation(Geocoder.java:136)
10-07 07:18:57.670 2694-2694/com.unalfaruk.mapexample W/System.err: at com.unalfaruk.mapexample.MapsActivity$1.onLocationChanged(MapsActivity.java:71)
10-07 07:18:57.670 2694-2694/com.unalfaruk.mapexample W/System.err: at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:297)
When I try on AVD Manager and Google Play Services is enabled (No error):
10-07 14:20:14.769 3159-3159/com.unalfaruk.mapexample I/System.out: Your Location: 37.421998333333335 -122.08400000000002
10-07 14:20:15.220 3159-3159/com.unalfaruk.mapexample I/System.out: Your Adress: Address[addressLines=[0:"1600 Amphitheatre Parkway",1:"Mountain View, CA 94043",2:"USA"],feature=1600,admin=California,sub-admin=null,locality=Mountain View,thoroughfare=Amphitheatre Parkway,postalCode=94043,countryCode=US,countryName=United States,hasLatitude=true,latitude=37.422329,hasLongitude=true,longitude=-122.0843055,phone=null,url=null,extras=null]
Upvotes: 0