Compass
The compass sensor, when present, provides a heading based on either True North or Magnetic North. True North is the direction to the geographic North Pole; Magnetic North is the direction to the magnetic north pole. The magnetic pole is not always in the same location because it shifts in response to changes in the Earth’s magnetic core. Listing 4.5 shows how to read the compass headings.
Listing 4.5: Reading Compass Headings
async private void ReadingChanged(object sender, CompassReadingChangedEventArgs e) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { CompassReading reading = e.Reading; ScenarioOutput_MagneticNorth.Text = String.Format("{0,5:0.00}", reading.HeadingMagneticNorth); if (reading.HeadingTrueNorth != null) { ScenarioOutput_TrueNorth.Text = String.Format("{0,5:0.00}", reading.HeadingTrueNorth); } else { ScenarioOutput_TrueNorth.Text = "No data"; } }); }
You can learn more about the compass sensor online at http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.sensors.compass.aspx.