我目前正在尝试获取当前用户的设备移动速度.这是我的代码:
import UIKit import Foundation import CoreLocation class ViewController: UIViewController,CLLocationManagerDelegate { let manager = CLLocationManager() var currentSpeed = 0.0 override func viewDidLoad() { super.viewDidLoad() manager.requestWhenInUseAuthorization() manager.delegate = self manager.desiredAccuracy = kCLLocationAccuracyHundredMeters manager.startUpdatingLocation() } func locationManager(manager: CLLocationManager,didUpdateLocations locations: [CLLocation]) { print(manager.location?.speed) } func locationManager(manager: CLLocationManager,didFailWithError error: NSError) { print("Error: \(error.localizedDescription)") }
唯一的问题是它打印“Optional(-1,0)”
我在这里先向您的帮助表示感谢.
解决方法
如果设备没有移动,或者移动得足够慢以至于数学没有意义,Core Location会给你一个负速度值.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。