swift - get accurate compass heading (magneticHeading and accuracy)
<p>I'm trying to get a single accurate value for a compass heading (which I then use with the gyro/accelerometer to calculate deviance).</p>

<p>Trouble is, if I stop updating the heading after the first result, I'm left with a heading value of 0.0?</p>

<p>I know some location services need to run for a while to give an accurate result, but how to implement this for newHeading.magneticHeading?</p>

<p>Any tips?  (I'm using CoreLocation with CLLocation Manager)</p>

<pre><code>func locationManager(manager: CLLocationManager,
    didUpdateHeading newHeading: CLHeading) {
        referenceHeading = newHeading.magneticHeading
        print("New reference heading = \(newHeading.magneticHeading)")
        gotReferenceHeading = true
        locationManager.stopUpdatingHeading()
}
</code></pre>