简体   繁体   中英

Android: grpc failed on Nexus 5

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.

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

我在Nexus 5X上遇到了同样的问题,原因在于使用VPN。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM