In this recipe, we will learn how to use the built-in compass to determine the heading of the device.
Create a new Single View Application in Xamarin Studio and name it HeadingApp
. Just as you did in the previous recipe, add two buttons and a label on the view of the controller.
Perform the following steps to determine the heading of the device:
Add the following code in the
HeadingAppViewController
class:private CLLocationManager locationManager; public override void ViewDidLoad () { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. this.locationManager = new CLLocationManager(); this.locationManager.UpdatedHeading += LocationManager_UpdatedHeading; this.locationManager.Failed += (sender, e) => Console.WriteLine("Failed! {0}", e.Error.LocalizedDescription); ...