locationRequest=LocationRequest.create(); //create() 函数无法识别,我正在使用最新版本 com.google.android.gms:play-services-location:21.1.0 但仍然收到此错误,请解决我的查询。
我正在我的android项目中实现gps启用和禁用程序
private var fusedLocationProvider: FusedLocationProviderClient? = null
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED
) {
val locationRequest: LocationRequest = LocationRequest.create().apply {
interval = getCaptureInterval() * 1000
fastestInterval = getCaptureInterval() * 1000
priority = Priority.PRIORITY_BALANCED_POWER_ACCURACY
maxWaitTime = getCaptureInterval() * 60 * 1000 // 10 minutes in milliseconds
smallestDisplacement = 20f
}
fusedLocationProvider?.requestLocationUpdates(
locationRequest,
locationCallback,
Looper.getMainLooper()
)
}
我在我的服务类中使用此功能进行位置请求
实现“com.google.android.gms:play-services-location:21.0.1”
我在 gradle 中使用的这个依赖项
注意:LocationRequest.create() 已被弃用,但我仍然在寻找最新的,如果我得到的话,会在这里更新这个答案是我的建议,试试这个