We will now learn how to receive the location information from the built-in GPS hardware.
Create a new Single View Application in Xamarin Studio and name it LocationApp
. Add two buttons and a label on the view of the controller.
Perform the following steps to receive the location of the device:
To retrieve location information from the built-in GPS hardware, we need to use the Core Location framework. It is exposed through the
MonoTouch.CoreLocation
namespace as follows:using MonoTouch.CoreLocation;
Add the following code in the
LocationAppViewController
class:private CLLocationManager locationManager; public override void ViewDidLoad () { base.ViewDidLoad (); this.locationManager = new CLLocationManager(); this.locationManager.LocationsUpdated += LocationManager_LocationsUpdated; this.locationManager.Failed += this.LocationManager_Failed; this.btnStart.TouchUpInside += delegate { this.lblOutput.Text = "Determining location......