swift – CoreLocation用户速度

swift – CoreLocation用户速度,第1张

概述我目前正在尝试获取当前用户的设备移动速度.这是我的代码: import UIKitimport Foundationimport CoreLocationclass ViewController: UIViewController, CLLocationManagerDelegate {let manager = CLLocationManager()var currentSpeed 我目前正在尝试获取当前用户的设备移动速度.这是我的代码:

import UIKitimport Foundationimport CoreLocationclass VIEwController: UIVIEwController,CLLocationManagerDelegate {let manager = CLLocationManager()var currentSpeed = 0.0overrIDe 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会给你一个负速度值.

https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/#//apple_ref/occ/instp/CLLocation/speed

总结

以上是内存溢出为你收集整理的swift – CoreLocation用户速度全部内容,希望文章能够帮你解决swift – CoreLocation用户速度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/999835.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存