The accelerometer is not the only sensor that can be used by UWP applications. The second one that is presented in this chapter is a compass. It allows you to get a heading relative to the magnetic north or geographic true north, if available. Of course, such a heading is returned in degrees. You will learn how to obtain values from a compass sensor in this recipe.
As an example, you will create an application that presents a compass rose that rotates according to the current heading relative to the magnetic north.
To prepare an example of rotating a compass rose according to data obtained from the compass sensor, perform the following steps:
Add the
CompassBackground.png
andCompassIndicator.png
files to theAssets
directory. These.png
files are available together with the code attached to this chapter.Add two
Image
controls, representing compass background...