无法解析“ FusedLocationProviderClientClient”中的方法“ getCurrentLocation”

问题描述

我正在尝试使用FusedLocationProviderClient.getCurrentLocation()

根据文档here应该可以使用它。

但是在Android Studio中,我收到了错误消息

无法在'FusedLocationProviderClient'中解析方法'getCurrentLocation'

我知道推荐的方法是实现requestLocationUpdates(),但这不是我想要的。

解决方法

您必须至少更新到Google Play定位服务api的17.1.0版本。在您的build.gradle(应用程序)中添加以下行:

implementation "com.google.android.gms:play-services-location:17.1.0"