Android: grpc failed on Nexus 5
Asked Answered
B

2

10

I'm working with geocoder. On all devices the code works fine but on a Nexus 5 phone there is an exception in the logs.

My code:

override fun fromAddress(address: Address): Observable<Geolocation> {
    val location = geocoder.getFromLocationName("${address.street} ${address.number}, ${address.postcode}, ${address.city}", LOCATIONS_MAX_RESULTS).first()
    return Observable.just(Geolocation(latitude = location.latitude, longitude = location.longitude))
}

My Error:

java.io.IOException: grpc failed
  at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
  at nl.ah.appienow.data.address.AndroidGeocoder.fromAddress(AndroidGeocoder.kt:20)
  at nl.ah.appienow.address.ValidatePostcode$execute$1.apply(ValidatePostcode.kt:31)
  at nl.ah.appienow.address.ValidatePostcode$execute$1.apply(ValidatePostcode.kt:17)
  at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.onNext(ObservableFlatMap.java:121)
  at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:64)
  at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:51)
  at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:37)
  at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:43)
  at io.reactivex.Observable.subscribe(Observable.java:10842)
  at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
  at io.reactivex.Observable.subscribe(Observable.java:10842)
  at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:33)
  at io.reactivex.Observable.subscribe(Observable.java:10842)
  at io.reactivex.internal.operators.observable.ObservableFlatMap.subscribeActual(ObservableFlatMap.java:55)
  at io.reactivex.Observable.subscribe(Observable.java:10842)
  at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
  at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
  at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
  at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
  at java.lang.Thread.run(Thread.java:818)

I read everywhere the solution reinstall Android studio or update Android studio but this doesn't works for me.

Bushweller answered 30/10, 2017 at 15:51 Comment(2)
Which version of playservices are you usingg? Which Android version is the Nexus 5 running? Have the other devices you tested with the same Android version installed ?Huckaby
Is that the only exception in the log? Is there no cause exception?Burning
E
0

I faced the same issue when i was getting address from latitude and longitude. I was using emulator and another truck screen device. On both devices It gives the same problem. GRPC failed. But when I run this code on my mobile and another Samsung device, It worked perfectly. I have to run it on that truck screen device. So I found a solution that to use Google Maps Location API to get location from latitude and longitude.

String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng="+log.getLattitude()+","+log.getLongitude()+"&key="+context.getResources().getString(R.string.geocodeAPiKey);

or simply

String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=33.25845,75.256489&key=API_KEY;

You can search for this like Reverse Geocoding

By this link you can get API Key for Geocoding

https://developers.google.com/maps/documentation/geocoding/get-api-key

In the result you will get a JSONObject. Get its first element in the JSONArray, and get the address from it like this

    JSONObject info = new JSONObject(result);
    JSONObject locationInfo = info.getJSONArray("results").getJSONObject(0);
    String locationDescription = locationInfo.getString("formatted_address");

This is reverse Geocoding. If you want to do simple Geocoding. Its almost same like this. I had the Reverse Geocoding code so i had shared that with you.

For more help and support please visit this link Google Geocoding API

Emmett answered 8/11, 2017 at 5:49 Comment(0)
W
0

I faced the same issue on Nexus 5X and a cause was in using VPN.

Wattmeter answered 11/12, 2017 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.