【发布时间】:2021-06-03 23:03:13
【问题描述】:
我最近偶然发现了这条消息,我很确定这个构造函数在 18.0.0 之前的版本中没有被弃用,但是我在任何地方都找不到这个被弃用的信息。
我们应该改用什么,有没有另一种方法来创建locationRequest?
【问题讨论】:
标签: android kotlin google-maps-android-api-2 google-location-services
我最近偶然发现了这条消息,我很确定这个构造函数在 18.0.0 之前的版本中没有被弃用,但是我在任何地方都找不到这个被弃用的信息。
我们应该改用什么,有没有另一种方法来创建locationRequest?
【问题讨论】:
标签: android kotlin google-maps-android-api-2 google-location-services
是的,LocationRequest 构造函数已弃用。您可以使用其静态方法LocationRequest.create() 来创建位置请求。
科特林:
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);
【讨论】:
setWaitForAccurateLocation(true) 添加到您的 LocationRequest。
LocationRequest locationRequest = LocationRequest.create() //if you want access of variable
.setInterval(100)
.setFastestInterval(3000)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setNumUpdates(1)
.setMaxWaitTime(100);
【讨论】: