【发布时间】:2018-12-05 21:30:13
【问题描述】:
我正在尝试计算用户当前的驾驶速度,但是 cllocationmanager 速度和实际驾驶速度之间存在巨大差异。
当我以 50 公里/小时的速度行驶时,配置管理器显示 ~72/~73 公里/小时。下面是我正在使用的代码。
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager.requestWhenInUseAuthorization()
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = false
locationManager.distanceFilter = 1.0
locationManager.headingFilter = 0.1
locationManager.startUpdatingLocation()
下面是位置管理器协议
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
let speedInKmph = location.speed * 3.6
if speedInKmph > 10 {
MyRide.shared.speedInfo.append(SpeedInfo(speed: speedInKmph))
self.view.showToast("\(speedInKmph) **********", position: .bottom, popTime: 2.0, dismissOnTap: false)
}
}
【问题讨论】:
-
你在哪里得到这个
location.speed,我觉得你需要使用manager.location?.speed -
这是位置数组中的最后一个对象。地点:[CLLocation]。
标签: ios swift cllocationmanager