public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            locMan = new CLLocationManager();
            locMan.RequestWhenInUseAuthorization();
            locMan.RequestAlwaysAuthorization();
            // Geocode a city to get a CLCircularRegion,
            // and then use our location manager to set up a geofence
            button.TouchUpInside += (o, e) => {
                // clean up monitoring of old region so they don't pile up
                if (region != null)
                {
                    locMan.StopMonitoring(region);
                }

                // Geocode city location to create a CLCircularRegion - what we need for geofencing!
                var taskCoding = geocoder.GeocodeAddressAsync("Cupertino");
                taskCoding.ContinueWith((addresses) => {
                    CLPlacemark placemark = addresses.Result [0];
                    region = (CLCircularRegion)placemark.Region;
                    locMan.StartMonitoring(region);
                });
            };


            // This gets called even when the app is in the background - try it!
            locMan.RegionEntered += (sender, e) => {
                Console.WriteLine("You've entered the region");
            };

            locMan.RegionLeft += (sender, e) => {
                Console.WriteLine("You've left the region");
            };
        }
        void AddRegion(GeofenceCircularRegion region)
        {
            CLRegion cRegion = null;


            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
            }
            else
            {
                cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
            }


            cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay;
            cRegion.NotifyOnExit  = region.NotifyOnExit;


            locationManager.StartMonitoring(cRegion);

            // Request state for this region, putting request behind a timer per thread: http://stackoverflow.com/questions/24543814/diddeterminestate-not-always-called
            Task.Run(async() => {
                await Task.Delay(TimeSpan.FromSeconds(2));
                locationManager.RequestState(cRegion);
            });
        }
        void didTapSaveButton(UIBarButtonItem sender)
        {
            double     circleDegreeDelta;
            CLLocation pointOnCircle;

            var span = MapView.Region.Span;

            if (span.LatitudeDelta > span.LongitudeDelta)
            {
                circleDegreeDelta = span.LongitudeDelta / MapRegionFraction;
                pointOnCircle     = new CLLocation(MapView.Region.Center.Latitude, MapView.Region.Center.Longitude - circleDegreeDelta);
            }
            else
            {
                circleDegreeDelta = span.LatitudeDelta / MapRegionFraction;
                pointOnCircle     = new CLLocation(MapView.Region.Center.Latitude - circleDegreeDelta, MapView.Region.Center.Longitude);
            }

            var mapCenterLocation = new CLLocation(MapView.Region.Center.Latitude, MapView.Region.Center.Longitude);
            var distance          = pointOnCircle.DistanceFrom(mapCenterLocation);
            var genericRegion     = new CLCircularRegion(MapView.Region.Center, distance, CircularRegion);

            circleOverlay = MKCircle.Circle(genericRegion.Center, genericRegion.Radius);
            var vcDelegate = Delegate;

            if (vcDelegate != null)
            {
                vcDelegate.MapViewDidUpdateRegion(genericRegion);
            }
            DismissViewController(true, null);
        }
Example #4
0
		public void StopMonitoringRegion(CLCircularRegion region)
		{
			if (CLLocationManager.LocationServicesEnabled) {

				if (CLLocationManager.Status != CLAuthorizationStatus.Denied) {

					if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion))) {

						LocMgr.StopMonitoring (region);
						Console.WriteLine ("Stopped monitoring region: {0}", region.ToString ());

					} else {

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

					// Get some output from our manager in case of failure
					LocMgr.Failed += (o, e) => {
						Console.WriteLine (e.Error);
					}; 

				} else {
					Console.WriteLine ("App is not authorized to use location data");
				}

			} else {
				//Let the user know that they need to enable LocationServices
				Console.WriteLine ("Location services not enabled, please enable this in your Settings");
			}
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            locMan = new CLLocationManager();
            locMan.RequestWhenInUseAuthorization();
            locMan.RequestAlwaysAuthorization();
            // Geocode a city to get a CLCircularRegion,
            // and then use our location manager to set up a geofence
            button.TouchUpInside += (o, e) => {

                // clean up monitoring of old region so they don't pile up
                if(region != null)
                {
                    locMan.StopMonitoring(region);
                }

                // Geocode city location to create a CLCircularRegion - what we need for geofencing!
                var taskCoding = geocoder.GeocodeAddressAsync ("Cupertino");
                taskCoding.ContinueWith ((addresses) => {
                    CLPlacemark placemark = addresses.Result [0];
                    region = (CLCircularRegion)placemark.Region;
                    locMan.StartMonitoring(region);

                });
            };

            // This gets called even when the app is in the background - try it!
            locMan.RegionEntered += (sender, e) => {
                Console.WriteLine("You've entered the region");
            };

            locMan.RegionLeft += (sender, e) => {
                Console.WriteLine("You've left the region");
            };
        }
Example #6
0
            public TrackedRegion(double latitude, double longitude, double radius, string description)
            {
                LandMarks = new List <CLRegion>( );

                Region   = new CLCircularRegion(new CLLocationCoordinate2D(latitude, longitude), radius, description);
                InRegion = false;
            }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            btnBeginCheckIn.BackgroundColor = new UIColor(new CoreGraphics.CGColor(0.1f,0.1f,0.1f));
            btnBeginCheckIn.Layer.CornerRadius = 1;
            btnBeginCheckIn.TouchUpInside += (object sender, EventArgs e) => {
                var locSvc = new ROMPLocation ();
                myFacilities = locSvc.GetLocations (sessionKey, groupID);
                string geofenceAnnounce = "Geofences Active At The Following Locations:\n";
                foreach (FacilityCoordinates fc in myFacilities) {
                    geofenceAnnounce += fc.LocationName + "\n";
                    var region = new CLCircularRegion (new CLLocationCoordinate2D (fc.Latitude, fc.Longitude), 50.0f, fc.LocationID.ToString());
                    geoMan.StartMonitoringRegion (region, locSvc, sessionKey, fc.LocationID, fc.LocationName);
                }
                UIAlertView _alert = new UIAlertView ("Monitoring Locations", geofenceAnnounce, null, "Ok", null);
                _alert.Show ();
                btnBeginCheckIn.Hidden = true;
                lblInfo.Text = "A record that you have checked-in will be made in the log of your education activity for this ROMP rotation when this device enters a 100m radius surrounding the facility of your ROMP rotation.";
            };

            btnExit.BackgroundColor = new UIColor(new CoreGraphics.CGColor(0.9f,0.9f,0.9f));
            btnExit.Layer.CornerRadius = 1;
            btnExit.TouchUpInside += (object sender, EventArgs e) => {
                Environment.Exit(0);
            };
        }
Example #8
0
        protected virtual GeofenceRegion FromNative(CLCircularRegion native)
        {
            var radius = Distance.FromMeters(native.Radius);
            var center = FromNative(native.Center);

            return(new GeofenceRegion(native.Identifier, center, radius));
        }
Example #9
0
        public void StopMonitoringRegion(CLCircularRegion region)
        {
            if (CLLocationManager.LocationServicesEnabled)
            {
                if (CLLocationManager.Status != CLAuthorizationStatus.Denied)
                {
                    if (CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
                    {
                        LocMgr.StopMonitoring(region);
                        Console.WriteLine("Stopped monitoring region: {0}", region.ToString());
                    }
                    else
                    {
                        Console.WriteLine("This app requires region monitoring, which is unavailable on this device");
                    }

                    // Get some output from our manager in case of failure
                    LocMgr.Failed += (o, e) => {
                        Console.WriteLine(e.Error);
                    };
                }
                else
                {
                    Console.WriteLine("App is not authorized to use location data");
                }
            }
            else
            {
                //Let the user know that they need to enable LocationServices
                Console.WriteLine("Location services not enabled, please enable this in your Settings");
            }
        }
Example #10
0
        partial void buttonCreateClicked(UIButton sender)
        {
            //CLRegion aRegion = new CLRegion();
            // locMan.StartMonitoring(aRegion);
            CLCircularRegion aRegion2 = new CLCircularRegion(new CLLocationCoordinate2D(30.432, 97.7360), 100, "apple test");

            locMan.StartMonitoring(aRegion2);
        }
        void AnnotateAndZoomToRegion(CLCircularRegion region)
        {
            circleOverlay = MKCircle.Circle(region.Center, region.Radius);
            const double multiplier = MapRegionFraction;
            var          mapRegion  = MKCoordinateRegion.FromDistance(region.Center, region.Radius * multiplier, region.Radius * multiplier);

            MapView.SetRegion(mapRegion, false);
        }
Example #12
0
        public virtual void StartMonitoringRegion()
        {
            StopMonitoringRegion();
            CLCircularRegion region = new CLCircularRegion(new CLLocationCoordinate2D(Location.Latitude, Location.Longitude), GeoFenceRadius, TollMinder);

            region.NotifyOnEntry = true;
            region.NotifyOnExit  = true;
            LocationManager.StartMonitoring(region, 1);
        }
Example #13
0
        public void StartMonitoringCircularRegion(Position centerPosition, double radius, string identifier)
        {
            var coordinate = new CLLocationCoordinate2D(centerPosition.Latitude, centerPosition.Longitude);
            var region     = new CLCircularRegion(coordinate, radius, identifier);

            if (_manager != null)
            {
                _manager.StartMonitoring(region);
                _logger?.Information($"iOS: Started monitoring: {identifier}");
            }
        }
Example #14
0
        // We need to perform a lot of checks to make sure location data and region monitoring are available and enabled.
        // For simplicity, we're logging errors in the console.

        public void StartMonitoringRegion(CLCircularRegion region)
        {
            Console.Write("Entro al monitoreo");
            Console.Write(CLLocationManager.LocationServicesEnabled);
            if (CLLocationManager.LocationServicesEnabled)
            {
                if (CLLocationManager.Status != CLAuthorizationStatus.Denied)
                {
                    if (CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
                    {
                        //LocMgr.DesiredAccuracy = 1;

                        LocMgr.RegionEntered += (o, e) => {
                            Console.WriteLine("Just entered " + e.Region.ToString());
                            RegionEntered(this, new RegionChangedEventArgs((CLCircularRegion)e.Region));
                        };

                        LocMgr.RegionLeft += (o, e) => {
                            Console.WriteLine("Just left " + e.Region.ToString());
                            RegionLeft(this, new RegionChangedEventArgs((CLCircularRegion)e.Region));
                        };

                        LocMgr.DidStartMonitoringForRegion += (o, e) => {
                            Console.WriteLine("Now monitoring region {0}", e.Region.ToString());
                        };

                        LocMgr.StartMonitoring(region);
                    }
                    else
                    {
                        Console.WriteLine("This app requires region monitoring, which is unavailable on this device");
                    }
                }
                else
                {
                    Console.WriteLine("App is not authorized to use location data");
                }

                // Get some output from our manager in case of failure
                LocMgr.Failed += (o, e) => {
                    Console.WriteLine(e.Error);
                };
            }
            else
            {
                //Let the user know that they need to enable LocationServices
                Console.WriteLine("Location services not enabled, please enable this in your Settings");
            }
        }
 public void MonitorRegionAtLocation(CLLocationCoordinate2D center, string identifier)
 {
     if (CLLocationManager.Status == CLAuthorizationStatus.AuthorizedAlways)
     {
         var maxDistance = LocMgr.MaximumRegionMonitoringDistance;
         var region      = new CLCircularRegion(center, maxDistance, identifier);
         region.NotifyOnEntry  = true;
         region.NotifyOnExit   = false;
         LocMgr.RegionEntered += (object sender, CLRegionEventArgs e) =>
         {
             RegionEntered(this, new DidEnterRegionEventArgs(e.Region));
         };
         LocMgr.StartMonitoring(region);
     }
 }
Example #16
0
        static void inicializaGeolocalizacion()
        {
            /*Se crean las variables de geolocalizacion*/
            CLGeocoder geocoder = new CLGeocoder();
            //CLCircularRegion region;19.285116, -99.675914
            CLCircularRegion  region = new CLCircularRegion(new CLLocationCoordinate2D(+19.285116, -99.675914), 100129.46, "Casa de toño");//19.273600, -99.675620
            CLLocationManager locMan;

            /*Se crean las variables de geolocalizacion*/


            locMan = new CLLocationManager();
            locMan.RequestWhenInUseAuthorization();
            locMan.RequestAlwaysAuthorization();
            // Geocode a city to get a CLCircularRegion,
            // and then use our location manager to set up a geofence

            // clean up monitoring of old region so they don't pile up
            Console.Write("Soy la region");
            Console.Write(region);
            Console.Write("termino soy la region");
            if (region != null)
            {
                locMan.StopMonitoring(region);
            }

            // Geocode city location to create a CLCircularRegion - what we need for geofencing!
            var taskCoding = geocoder.GeocodeAddressAsync("Cupertino");

            taskCoding.ContinueWith((addresses) => {
                CLPlacemark placemark = addresses.Result[0];
                region = (CLCircularRegion)placemark.Region;
                Console.Write("\nInicio el monitoreo ..........");
                locMan.StartMonitoring(region);
                Console.Write("\nTermino el monitoreo ..........");
            });


            // This gets called even when the app is in the background - try it!
            locMan.RegionEntered += (sender, e) => {
                Console.WriteLine("You've entered the region");
            };

            locMan.RegionLeft += (sender, e) => {
                Console.WriteLine("You've left the region");
            };
        }
Example #17
0
        // The user left the refresh zone.  Get a new catalog of bubbles from the server.
        async void Refresh(object sender, CLRegionEventArgs e)
        {
            if (credentials.BasicAuthString.Length > 0 && (e == null || e.Region.Identifier.Equals("RefreshZone"))) // Ignore location bubbles.
            {
                // Get the user's location and code it as the bubble zone.
                CLLocation location  = LocMgr.Location;
                double     latitude  = location.Coordinate.Latitude;  // TBD double
                double     longitude = location.Coordinate.Longitude; // TBD double
                Debug.WriteLine(">>>>> Refreshing at " + latitude.ToString() + ", " + longitude.ToString());
                Location loc = new Location(latitude, longitude);
                // Get all the bubbles in the zone.
                string json = await WebApiPost("api/Bubble", loc);

                BubbleCatalog = (List <BubbleMobile>)JsonConvert.DeserializeObject(json, typeof(List <BubbleMobile>));

                // At the last possible moment, delete all the existing bubbles.
                foreach (CLCircularRegion r in LocMgr.MonitoredRegions)
                {
                    LocMgr.StopMonitoring(r);
                }

                // Set an event handler for each bubble in the new list.
                foreach (BubbleMobile bubble in BubbleCatalog)
                {
                    if (bubble.Id == 0) // Refresh zone bubble.
                    {
                        Debug.WriteLine(">>>>> Adding refresh zone");
                        // Redefine the refresh zone and give it an event handler.
                        CLCircularRegion refreshRegion = new CLCircularRegion(new CLLocationCoordinate2D(latitude, longitude), bubble.Radius, "RefreshZone");
                        LocMgr.StartMonitoring(refreshRegion);
                    }
                    else // Poppable bubble.
                    {
                        CLCircularRegion bubbleRegion = new CLCircularRegion(new CLLocationCoordinate2D((double)bubble.Latitude, (double)bubble.Longitude), bubble.Radius, bubble.Id.ToString());
                        LocMgr.StartMonitoring(bubbleRegion);
                        Debug.WriteLine(">>>>> Adding bubble #" + bubble.Id.ToString());
                        // Check to see if we're already inside the bubble.  This will not raise a "RegionEntered" event.
                        if (bubbleRegion.Contains(new CLLocationCoordinate2D(latitude, longitude)))
                        {
                            Debug.WriteLine(">>>>> Inside bubble #" + bubble.Id.ToString() + " before pop");
                            Pop(null, new CLRegionEventArgs(bubbleRegion));
                            Debug.WriteLine(">>>>> Inside bubble #" + bubble.Id.ToString() + " after pop");
                        }
                    }
                }
            }
        }
Example #18
0
		// We need to perform a lot of checks to make sure location data and region monitoring are available and enabled.
		// For simplicity, we're logging errors in the console.

		public void StartMonitoringRegion (CLCircularRegion region)
		{
			if (CLLocationManager.LocationServicesEnabled) {

				if (CLLocationManager.Status != CLAuthorizationStatus.Denied) {

					if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion))) {

						//LocMgr.DesiredAccuracy = 1;

						LocMgr.RegionEntered += (o, e) => {
							Console.WriteLine ("Just entered " + e.Region.ToString ());
							RegionEntered (this, new RegionChangedEventArgs ((CLCircularRegion)e.Region));
						};

						LocMgr.RegionLeft += (o, e) => {
							Console.WriteLine ("Just left " + e.Region.ToString ());
							RegionLeft (this, new RegionChangedEventArgs ((CLCircularRegion)e.Region));
						};

						LocMgr.DidStartMonitoringForRegion += (o, e) => {
							Console.WriteLine ("Now monitoring region {0}", e.Region.ToString ());
						};
							
						LocMgr.StartMonitoring (region);

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

				} else {
					Console.WriteLine ("App is not authorized to use location data");
				}

				// Get some output from our manager in case of failure
				LocMgr.Failed += (o, e) => {
					Console.WriteLine (e.Error);
				}; 

			} else {

				//Let the user know that they need to enable LocationServices
				Console.WriteLine ("Location services not enabled, please enable this in your Settings");

			}
		}
Example #19
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			// Perform any additional setup after loading the view, typically from a nib.

			var LocationManager = new CLLocationManager();
			LocationManager.RequestWhenInUseAuthorization ();
			LocationManager.RequestAlwaysAuthorization ();

			CLCircularRegion region = new CLCircularRegion (new CLLocationCoordinate2D (+46.833120, +15.34901), 1000.0, "FF Gussendorf");

			if (CLLocationManager.LocationServicesEnabled) {

				LocationManager.DidStartMonitoringForRegion += (o, e) => {
					Console.WriteLine ("Now monitoring region {0}", e.Region.ToString ());
				};

				LocationManager.RegionEntered += (o, e) => {
					Console.WriteLine ("Just entered " + e.Region.ToString ());
				};

				LocationManager.RegionLeft += (o, e) => {
					Console.WriteLine ("Just left " + e.Region.ToString ());
				};

				LocationManager.Failed += (o, e) => {
					Console.WriteLine (e.Error);
				};

				LocationManager.UpdatedLocation += (o, e) => {
					Console.WriteLine ("Lat " + e.NewLocation.Coordinate.Latitude + ", Long " + e.NewLocation.Coordinate.Longitude);
				};

				LocationManager.LocationsUpdated += (o, e) => Console.WriteLine ("Location change received");

				LocationManager.StartMonitoring (region);
				LocationManager.StartMonitoringSignificantLocationChanges ();

				//LocationManager.StopMonitoringSignificantLocationChanges ();



			} else {
				Console.WriteLine ("This app requires region monitoring, which is unavailable on this device");
			}
		}
        public static void SetRegions(List <CLCircularRegion> regions, CLCircularRegion updateRegion = null)
        {
            //убираем предыдущие регионы
            foreach (var region in _locationManager.MonitoredRegions.OfType <CLCircularRegion>())
            {
                _locationManager.StopMonitoring(region);
            }

            if (regions != null && regions.Count > 0)
            {
                foreach (var region in regions)
                {
                    _locationManager.StartMonitoring(region);
                }

                //задаем регион при выходи за границы которого обновляются точки
                if (updateRegion != null)
                {
                    _locationManager.StartMonitoring(updateRegion);
                }
            }
        }
        void AddRegion(GeofenceCircularRegion region)
        {
            CLRegion cRegion = null;


            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
            }
            else
            {
                cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
            }


            cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay;
            cRegion.NotifyOnExit  = region.NotifyOnExit;



            locationManager.StartMonitoring(cRegion);
            locationManager.RequestState(cRegion);
        }
Example #22
0
 protected virtual GeofenceRegion FromNative(CLCircularRegion native)
 {
     return new GeofenceRegion
     {
         Identifier = native.Identifier,
         Center = this.FromNative(native.Center),
         Radius = Distance.FromMeters(native.Radius)
     };
 }
 public void MapViewDidUpdateRegion(CLCircularRegion region)
 {
     TargetRegion = region;
 }
      void AddRegion(GeofenceCircularRegion region)
      {
          CLRegion cRegion = null;


          if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
          {
              cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
          }
          else
          {
              cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
          }


          cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay;
          cRegion.NotifyOnExit = region.NotifyOnExit;



          locationManager.StartMonitoring(cRegion);
          locationManager.RequestState(cRegion);
      }
Example #25
0
		// We need to perform a lot of checks to make sure location data and region monitoring are available and enabled.
		// For simplicity, we're logging errors in the console.

		public void StartMonitoringRegion (CLCircularRegion region, ROMPLocation rompLoc, string sessionKey, int locationID, string locationName)
		{
			if (CLLocationManager.LocationServicesEnabled) {

				if (CLLocationManager.Status != CLAuthorizationStatus.Denied) {

					if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion))) {

						//LocMgr.DesiredAccuracy = 1;

						FenceMgr.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;


						if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
						{
							FenceMgr.RequestAlwaysAuthorization ();
						}

						var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge, null);
						UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);

						FenceMgr.RegionEntered += (o, e) => {
							rompLoc.CheckIn(sessionKey, locationID);
							Console.WriteLine ("Just entered " + e.Region.ToString ());
							UILocalNotification notification = new UILocalNotification();
							DateTime date = DateTime.Now.AddSeconds(5.0);
							date = date.ToLocalTime();
							NSDate nsDate = (NSDate)DateTime.SpecifyKind(date, DateTimeKind.Utc);
							notification.FireDate = nsDate;
							notification.AlertAction = "Check In";
							notification.AlertBody = "Successfully Checked Into " + locationName;
							UIApplication.SharedApplication.ScheduleLocalNotification(notification);
							RegionEntered (this, new RegionChangedEventArgs ((CLCircularRegion)e.Region));
						};

						FenceMgr.RegionLeft += (o, e) => {
							rompLoc.CheckOut(sessionKey, locationID);
							Console.WriteLine ("Just left " + e.Region.ToString ());
							UILocalNotification notification = new UILocalNotification();
							DateTime date = DateTime.Now.AddSeconds(5.0);
							date = date.ToLocalTime();
							NSDate nsDate = (NSDate)DateTime.SpecifyKind(date, DateTimeKind.Utc);
							notification.FireDate = nsDate;
							notification.AlertAction = "Check Out";
							notification.AlertBody = "Successfully Checked Out Of " + locationName;
							UIApplication.SharedApplication.ScheduleLocalNotification(notification);
							RegionLeft (this, new RegionChangedEventArgs ((CLCircularRegion)e.Region));
						};

						FenceMgr.DidStartMonitoringForRegion += (o, e) => {
							Console.WriteLine ("Now monitoring region {0}", e.Region.ToString ());
						};

						FenceMgr.StartMonitoring (region);

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

				} else {
					Console.WriteLine ("App is not authorized to use location data");
				}

				// Get some output from our manager in case of failure
				FenceMgr.Failed += (o, e) => {
					Console.WriteLine (e.Error);
				}; 

			} else {

				//Let the user know that they need to enable LocationServices
				Console.WriteLine ("Location services not enabled, please enable this in your Settings");

			}
		}
		public void MapViewDidUpdateRegion (CLCircularRegion region)
		{
			TargetRegion = region;
		}
      void AddRegion(GeofenceCircularRegion region)
      {
          CLRegion cRegion = null;


          if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
          {
              cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
          }
          else
          {
              cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
          }


          cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay;
          cRegion.NotifyOnExit = region.NotifyOnExit;


          locationManager.StartMonitoring(cRegion);

          // Request state for this region, putting request behind a timer per thread: http://stackoverflow.com/questions/24543814/diddeterminestate-not-always-called
          Task.Run(async() => {
              await Task.Delay(TimeSpan.FromSeconds(2));
              locationManager.RequestState(cRegion);
          });
      }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            CLCircularRegion region = new CLCircularRegion(new CLLocationCoordinate2D(10.009176843388, 76.3615990792536), 20.0, "Jubin's Desk");

            locLabel = (UILabel)this.View.ViewWithTag(2004);
            locLabel1 = (UILabel)this.View.ViewWithTag(2005);
            statusLabel = (UILabel)this.View.ViewWithTag(2006);
            locLabel.Text = "Location...";
            locManager = new CLLocationManager();
            locManager.RequestAlwaysAuthorization ();
            //locManager.RequestWhenInUseAuthorization ();
            locManager.DesiredAccuracy = CLLocation.AccuracyBest;
            //locManager.DistanceFilter = 5.0;
            locManager.UpdatedLocation+=(object sender, CLLocationUpdatedEventArgs e) => {
                locLabel.Text = "Longitude: "+e.NewLocation.Coordinate.Longitude+" Lattitude: "+e.NewLocation.Coordinate.Latitude;
                System.Diagnostics.Debug.WriteLine("Longitude: "+e.NewLocation.Coordinate.Longitude+" Lattitude: "+e.NewLocation.Coordinate.Latitude);
            };
            /* this gets fired and works fine */
            locManager.LocationsUpdated+=(object sender, CLLocationsUpdatedEventArgs e) => {
                foreach (CLLocation aLocation in e.Locations)
                {
                    locLabel1.Text = "Longitude: "+aLocation.Coordinate.Longitude.ToString()+" Lattitude: "+aLocation.Coordinate.Latitude.ToString();
                    if (region.ContainsCoordinate(new CLLocationCoordinate2D(aLocation.Coordinate.Latitude, aLocation.Coordinate.Longitude)))
                    {
                        statusLabel.Text = "Normal location update: cordinates inside the region";
                    }
                    else
                    {
                        statusLabel.Text = "Normal location update: cordinates outside the region";
                    }
                }
            };
            locManager.StartUpdatingLocation();

            if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion)))
            {
                /* This doesn't get fired */
                locManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {
                    switch(e.State)
                    {
                        case CLRegionState.Inside:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Iniside...";
                            UIAlertView testAlert = new UIAlertView ();
                            testAlert.AddButton ("OK");
                            testAlert.Title = "Entered";
                            testAlert.Message = "Region "+e.Region.ToString();
                            testAlert.Show();
                        });
                        break;

                        case CLRegionState.Outside:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Outside...";
                            UIAlertView testAlert1 = new UIAlertView ();
                            testAlert1.AddButton ("OK");
                            testAlert1.Title = "Exit";
                            testAlert1.Message = "Region "+e.Region.ToString();
                            testAlert1.Show();
                        });
                        break;

                        case CLRegionState.Unknown:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Unknown state for region...";
                        });
                        break;
                        default:
                        break;
                    }
                };
                /* This works and gets fired */
                locManager.DidStartMonitoringForRegion += (o, e) => {
                    InvokeOnMainThread(()=>{
                        locManager.RequestState(e.Region);
                        locLabel.Text = "Now monitoring region : "+ e.Region.ToString ();
                    });
                };
                /* This doesn't get fired */
                locManager.DidVisit+=(object sender, CLVisitedEventArgs e) => {
                    InvokeOnMainThread(()=>{
                        locLabel.Text = "Did visit region...";
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Visited";
                        testAlert.Message = "Region "+e.Visit.Coordinate.Latitude.ToString()+" | "+e.Visit.Coordinate.Longitude.ToString();
                        testAlert.Show();
                    });
                };
                /* This doesn't get fired */
                locManager.RegionEntered += (o, e) => {
                    InvokeOnMainThread(()=>{
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Entered";
                        testAlert.Message = "Region "+e.Region.ToString();
                        testAlert.Show();
                        locLabel.Text = "Entered: "+e.Region.ToString();
                    });
                };
                /* This doesn't get fired */
                locManager.RegionLeft += (o, e) => {
                    InvokeOnMainThread(()=>{
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Exit";
                        testAlert.Message = "Region "+e.Region.ToString();
                        testAlert.Show();
                        locLabel.Text = "Left: "+e.Region.ToString();
                    });
                };
                locManager.StartMonitoring (region);
            }
            else
            {
            }
            // Perform any additional setup after loading the view, typically from a nib.
        }
		void AnnotateAndZoomToRegion (CLCircularRegion region)
		{
			circleOverlay = MKCircle.Circle (region.Center, region.Radius);
			const double multiplier = MapRegionFraction;
			var mapRegion = MKCoordinateRegion.FromDistance (region.Center, region.Radius * multiplier, region.Radius * multiplier);
			MapView.SetRegion (mapRegion, false);
		}
		void didTapSaveButton (UIBarButtonItem sender)
		{
			double circleDegreeDelta;
			CLLocation pointOnCircle;

			var span = MapView.Region.Span;
			if (span.LatitudeDelta > span.LongitudeDelta) {
				circleDegreeDelta = span.LongitudeDelta / MapRegionFraction;
				pointOnCircle = new CLLocation (MapView.Region.Center.Latitude, MapView.Region.Center.Longitude - circleDegreeDelta);
			} else {
				circleDegreeDelta = span.LatitudeDelta / MapRegionFraction;
				pointOnCircle = new CLLocation (MapView.Region.Center.Latitude - circleDegreeDelta, MapView.Region.Center.Longitude);
			}

			var mapCenterLocation = new CLLocation (MapView.Region.Center.Latitude, MapView.Region.Center.Longitude);
			var distance = pointOnCircle.DistanceFrom (mapCenterLocation);
			var genericRegion = new CLCircularRegion (MapView.Region.Center, distance, CircularRegion);

			circleOverlay = MKCircle.Circle (genericRegion.Center, genericRegion.Radius);
			var vcDelegate = Delegate;
			if (vcDelegate != null)
				vcDelegate.MapViewDidUpdateRegion (genericRegion);
			DismissViewController (true, null);
		}
 public RegionChangedEventArgs(CLCircularRegion region)
 {
     this.region = region;
 }
		static CLCircularRegion CreateNativeRegion (Region region, string identifier)
		{
			var center = new CLLocationCoordinate2D {
				Longitude = region.Longitude,
				Latitude = region.Latitude
			};
			var clCircularRegion = new CLCircularRegion (center, region.AlertZoneRadiusInMeters, identifier);
			return clCircularRegion;
		}
Example #33
0
 public RegionChangedEventArgs(CLCircularRegion region)
 {
     this.region = region;
 }
 static CLRegionEventArgs CreateRegion()
 {
     var coord = new CLLocationCoordinate2D ();
     var region = new CLCircularRegion (coord, 1, "2");
     return new CLRegionEventArgs (region);
 }
Example #35
0
 public Flyover(CLCircularRegion circularRegion)
 {
     Coordinate = circularRegion.Center;
 }