简体   繁体   English

Android:在Nexus 5上grpc失败了

[英]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. 在所有设备上,代码工作正常,但在Nexus 5手机上,日志中有例外。

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. 我随处可读解决方案重新安装Android工作室或更新Android工作室,但这对我不起作用。

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. GRPC失败了。 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. 所以我找到了一个解决方案,使用Google Maps Location API从纬度和经度获取位置。

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 通过此链接,您可以获得地理编码的 API密钥

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

In the result you will get a JSONObject. 在结果中,您将获得一个JSONObject。 Get its first element in the JSONArray, and get the address from it like this 获取它在JSONArray中的第一个元素,并从中获取它的地址

    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 如需更多帮助和支持,请访问此链接Google Geocoding API

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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