2

Is there any information whether one can receive the 'heading' of the Apple Watch?

I would like to display an arrow where the user needs to go, relative to the way he is currently holding the watch. On the iPhone you can do this using the CLLocationManager-heading, but I'm not sure whether/how this will work on Apple Watch (I don't need the iPhone heading ;) )

Is there any documentation on this that you can link me to?

Nils Ziehn
  • 4,118
  • 6
  • 26
  • 40
  • 1
    For everyone reading this: The Apple Watch doesn't even have a magnetometer - so no compass data. :( – Nils Ziehn Mar 29 '15 at 12:05
  • possible duplicate of [Using Core Location in Apple WatchKit](http://stackoverflow.com/questions/27420439/using-core-location-in-apple-watchkit) – newenglander Apr 28 '15 at 15:07

3 Answers3

3

You can now by using "magneticHeading" or "trueHeading" from Core Location (Apple Watch Serie 5+, watchOS 6.0+)

Here is a basic example:

import CoreLocation

class yourClass {
    let locationManager = CLLocationManager()

    init() {
        setupCoreLocation()
    }

    func setupCoreLocation() {
        guard CLLocationManager.headingAvailable() else { return }
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        // additional setup available if needed
    }
}

extension yourClass: CLLocationManagerDelegate {
    func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
        let magneticHeading = newHeading.magneticHeading
        let trueHeading = newHeading.trueHeading
        // Do something with the new heading values
    }
}

Then when you need the heading values you do:

locationManager.startUpdatingHeading()

And when you don't need them anymore you do:

locationManager.stopUpdatingHeading()

Here are all the official Apple documentations:

Core Location

CLHeading

magneticHeading

trueHeading

Heading and Course Information basic knowledge

Don't forget to check if "heading" is available first: headingAvailable()

AW5
  • 406
  • 3
  • 12
2

No compass in the Apple watch... you could guess the heading based on successive GPS locations (GPS is also running on iphone...) relying on the compass of the iPhone is probably not suitable !

Xav
  • 270
  • 3
  • 13
1

Since WatchKit doesn't provide access to Apple Watch's hardware (and there's no magnetometer in the watch, anyway), you'd be dealing with the heading of the phone.

As such, getting getting an accurate heading while standing still isn't currently feasible. However, if you're okay with requiring some movement first, you can calculate a bearing from several recorded location coordinates. Answers to this question (iOS) or this one (general math) might prove useful to you.

Community
  • 1
  • 1
macserv
  • 3,546
  • 1
  • 26
  • 36