Compass Orientation

The compass API uses a single axis to calculate the heading, depending on the orientation of the device. The device may be flat with its screen facing up, or it may be in an upright portrait position.

The Compass class does not provide the means to determine which orientation it is using; rather, you use an Accelerometer to tell you.

The viewmodel’s Start method also includes the initialization of an Accelerometer (see Listing 16.6).

LISTING 16.6. CompassViewModel.Start Method (excerpt 2)

public void Start(){    ...    accelerometer = new Accelerometer();    accelerometer.CurrentValueChanged += HandleAccelerometerCurrentValueChanged;    accelerometer.Start();}

The orientation of the compass ...

Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.