In this recipe, we will learn how to use GPS to respond to region-specific position changes.
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.
Perform the following steps:
Create two fields in the
RegionAppViewController
class as follows:private CLLocationManager locationManager; private CLCircularRegion region;
In the
ViewDidLoad
method, initialize theRegionAppViewController
class, and subscribe to theLocationsUpdated
,RegionEntered
, andRegionLeft
events as follows:this.locationManager.RegionEntered += this.LocationManager_RegionEntered; this.locationManager.RegionLeft += this.LocationManager_RegionLeft; this.locationManager.UpdatedLocation += this.LocationManager_UpdatedLocation;
Enter the following event handlers in the class:
private void LocationManager_LocationsUpdated (object sender, CLLocationUpdatedEventArgs e) { CLLocation location = e.Locations...