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

Using region monitoring


In this recipe, we will learn how to use GPS to respond to region-specific position changes.

Getting ready

Create a new Single View Application in Xamarin Studio and name it RegionApp. Add two buttons and a label on the view of the controller.

How to do it...

Perform the following steps:

  1. Create two fields in the RegionAppViewController class as follows:

    private CLLocationManager locationManager;
    private CLCircularRegion region;
  2. In the ViewDidLoad method, initialize the RegionAppViewController class, and subscribe to the LocationsUpdated, RegionEntered, and RegionLeft events as follows:

    this.locationManager.RegionEntered += this.LocationManager_RegionEntered;
    this.locationManager.RegionLeft += this.LocationManager_RegionLeft;
    this.locationManager.UpdatedLocation += this.LocationManager_UpdatedLocation;
  3. Enter the following event handlers in the class:

    private void LocationManager_LocationsUpdated (object sender, CLLocationUpdatedEventArgs e)
    {
      CLLocation location = e.Locations...