java 地理编码器 grpc 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45521579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:44:16  来源:igfitidea点击:

Geocoder grpc failed

javaandroidgoogle-geocoder

提问by Mackan

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 failedbut it didn't really solve the problem.

上个月的 so geocoder 每次都开始因“grpc failed”错误而失败,我似乎无法解决它。我看过java.io.IOException: grpc failed但它并没有真正解决问题。

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.

如果我针对 SDK 25 进行编译,使用构建工具 25 它可以在带有 SDK 25 的模拟器上运行。但是如果我尝试在带有 SDK 24、26 或任何其他 SDK 版本的模拟器上运行,它会因“grpc failed”而失败。我试图创建一个新的虚拟设备等,但同样的问题。

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)

当前设置:targetSDK/compileSDK 25,构建工具 25.0.3,Android Studio 2.3.3,常规模拟器。(我尝试过其他构建工具和 SDK 版本,但问题仍然存在)

Any ideas?

有任何想法吗?

回答by Cifus

The problem may be that you are trying to use Geocoder in the main thread, if you are using an IntentService you have this URLoption to create in another process although you can always use an Asynctask or similar.

问题可能是您尝试在主线程中使用 Geocoder,如果您使用的是 IntentService,您可以在另一个进程中创建此URL选项,尽管您始终可以使用 Asynctask 或类似的。

回答by user7764270

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

好吧,这可能为时已晚,对于正在寻找答案的其他人来说,就我而言,这是互联网问题。我的互联网连接不好

回答by Faruk üNAL

It's related to Google Play Service on virtual devices. Use API25 and version 7.1.1for solution.

它与虚拟设备上的 Google Play 服务有关。使用 API25 和 7.1.1 版本解决。

Here are examples;

以下是示例;

When I try on Genymotion and Google Play Services is disabledon virtual device (Error: Service not Available):

当我尝试使用 Genymotion 并且在虚拟设备上禁用 Google Play 服务时(错误:服务不可用):

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.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)

enter image description here

在此处输入图片说明

When I try on Genymotion and Google Play Services is enabled(Error: grpc failed):

当我尝试使用 Genymotion 并启用 Google Play 服务时(错误:grpc 失败):

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.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)

enter image description here

在此处输入图片说明

When I try on AVD Manager and Google Play Services is enabled(No error):

当我尝试使用 AVD 管理器并启用 Google Play 服务时(没有错误):

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]

enter image description here

在此处输入图片说明