Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Determining location


We will now learn how to receive the location information from the built-in GPS hardware.

Getting ready

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.

How to do it...

Perform the following steps to receive the location of the device:

  1. 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;
  2. 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......