android “构造函数LocationRequest()”在谷歌Mapv2中是否已弃用?

lvmkulzt  于 2022-11-03  发布在  Android
关注(0)|答案(6)|浏览(402)

我最近偶然发现了这条消息,我非常肯定这个构造函数在18.0.0之前的版本中没有被弃用,但是我在任何地方都找不到这个构造函数被弃用的信息。
我们应该用什么来代替,有没有其他方法来创建一个locationRequest

xdnvmnnf

xdnvmnnf1#

是的,LocationRequest建构函式已过时。您可以使用它的静态方法LocationRequest.create()来建立位置要求。
Kotlin:

locationRequest = LocationRequest.create().apply {
    interval = 100
    fastestInterval = 50
    priority = LocationRequest.PRIORITY_HIGH_ACCURACY
    maxWaitTime = 100
}

java 语:

locationRequest = LocationRequest.create()
    .setInterval(100)
    .setFastestInterval(3000) 
    .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
    .setMaxWaitTime(100);

更新

正如@Shimon所指出的,LocationRequest.PRIORITY_HIGH_ACCURACY现在已弃用,因此请改用Priority.PRIORITY_HIGH_ACCURACY

xhv8bpkk

xhv8bpkk2#

该行现在已弃用:优先级=位置请求。优先级_高_精度
替换为优先级=优先级.优先级_高_精度

d7v8vwbk

d7v8vwbk3#

对于任何在Flutter的geolocator 8.0.1中遇到这个错误的人。现在试着编辑FusedLocationClient.java:199。然后等待作者更新发布包
起始日期

LocationRequest locationRequest = new LocationRequest();

结束日期

LocationRequest locationRequest = LocationRequest.create();

这是LocationRequest

zed5wv10

zed5wv104#

更新日期:

常量 PRIORITY_HIGH_ACCURACY 已过时,请改用 Priority.PRIORITY_HIGH_ACCURACY

private fun updateLocationTracking(isTracking: Boolean) {
        if(isTracking) {
            if(TrackingUtility.hasLocationPermissions(this)) {
                val request = LocationRequest.create().apply {
                    interval = LOCATION_UPDATE_INTERVAL
                    fastestInterval = FASTEST_LOCATION_INTERVAL
                    priority =  Priority.PRIORITY_HIGH_ACCURACY
                }
}
f0brbegy

f0brbegy5#

LocationRequest.create().apply{ ... }现在也不建议使用。
请改用LocationRequest.Builder()。例如,如下所示:
locationIntervallocationFastestIntervallocationMaxWaitTime对应于之前使用create()时使用的值)

locationRequest = LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, locationInterval)
            .setWaitForAccurateLocation(false)
            .setMinUpdateIntervalMillis(locationFastestInterval)
            .setMaxUpdateDelayMillis(locationMaxWaitTime)
            .build()

请在此处阅读更多信息:https://developer.android.com/reference/android/location/LocationRequest.Builder

rggaifut

rggaifut6#

LocationRequest locationRequest = LocationRequest.create() //if you want access of variable
                            .setInterval(100)
                            .setFastestInterval(3000)
                            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                            .setNumUpdates(1)
                            .setMaxWaitTime(100);

相关问题