Problem in crating Geofence

Mahesh.5770Mahesh.5770 USMember ✭✭
edited January 2017 in Xamarin.iOS

Hi,

I am trying to create Geofence in xamarin forms project,
I tried CLLocationManager RegionEntered, RegionLeft callbacks and StartUpdatingLocations approaches using dependency service, unfortunately none of them worked,
Can some one help me out with this.

RegionEntered, RegionLeft callbacks
public void StartGeoFence ()
{
if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion))) {
locationManager.DidStartMonitoringForRegion += (o, e) => {
Console.WriteLine ("Now monitoring region {0}", e.Region);
UIAlertView alert = new UIAlertView();
alert.Title = "monitoring started";
alert.AddButton("Ok");
//alert.Show();
};

            locationManager.RegionEntered += (o, e) => {
                Console.WriteLine ("Just entered " + e.Region);
                UIAlertView alert = new UIAlertView();
                alert.Title = "entered region";
                alert.AddButton("Ok");
                alert.Show();
            };

            locationManager.RegionLeft += (o, e) => {
                Console.WriteLine ("Just left " + e.Region);
                UIAlertView alert = new UIAlertView();
                alert.Title = "lefted region";
                alert.AddButton("Ok");
                alert.Show();
            };

            locationManager.StartMonitoring (region);

        } else {
            Console.WriteLine ("This app requires region monitoring, which is unavailable on this device");
        }

}


StartUpdatingLocations

public void StartService()
{
if (CLLocationManager.LocationServicesEnabled)
{
locMgr = new CLLocationManager();

            locMgr.RequestWhenInUseAuthorization();

            locMgr.Delegate = this;
            locMgr.DesiredAccuracy = 10;
            locMgr.StartUpdatingLocation();
        }
    }

    [Export("locationManager:didUpdateToLocation:fromLocation:")]
    public void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation)
    {
        UIAlertView alert = new UIAlertView();
        alert.Title = "Location Upadated";
        alert.Message = "Latitude:" + newLocation.Coordinate.Latitude + " Longitude:" + newLocation.Coordinate.Longitude;
        alert.AddButton("Ok");
        alert.Show();
    }

Thanks,
Mahesh Kolluri

Tagged:
Sign In or Register to comment.