【发布时间】:2017-09-29 21:33:16
【问题描述】:
我目前只使用模拟器,但在 iOS 模拟器上快速使用 CoreLocation 时遇到问题。我得到此代码打印的位置更新,但从未标题。我不想要当然,我正在尝试制作一个指南针类型的应用程序,它将显示一个目标的方位。
class CompassViewController: UIViewController, CLLocationManagerDelegate {
var lm:CLLocationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
print ("view did load")
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest
lm.requestWhenInUseAuthorization()
lm.startUpdatingLocation()
lm.startUpdatingHeading()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
var locValue:CLLocationCoordinate2D = manager.location!.coordinate
var course = manager.location!.course
print("locations = \(locations)")
}
func headingManger(_ manager: CLLocationManager, didUpdateHeading: [CLHeading]) {
var heading = manager.heading?.magneticHeading
print("heading = \(heading)")
}
}
我尝试了几种组合方式。我尝试做一个同时处理位置和航向的函数,但根本没有打印任何数据。我也尝试过使用 headingManager 功能,但没有打印任何内容。上面的当前代码将打印位置,但不打印标题。
我怎样才能上班?
【问题讨论】:
-
获取航向需要带有指南针的设备,而模拟器没有。
-
那么只有在设备上使用 compass 测试应用程序的方法吗?
-
是的,您需要一个带有内置指南针的设备。
-
好的,现在我通过 X 代码在我的 iPhone 上运行相同的代码,但我仍然没有得到指南针方向。我的位置是输出,但不是指南针方向。
标签: ios swift core-location