void LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e) { CLLocation lastLocation = e.Locations[e.Locations.Length - 1]; SetLastKnownLocation(lastLocation); if (Regions.Count > 20 && locationManager.MonitoredRegions.Count == 20) { RecalculateRegions(); } else { //Check any current monitored regions not in loaded persistent regions and stop monitoring them foreach (CLCircularRegion region in locationManager.MonitoredRegions) { if (!Regions.ContainsKey(region.Identifier)) { locationManager.StopMonitoring(region); string message = string.Format("{0} - Stopped monitoring region {1} wasn't in persistent loaded regions", CrossGeofence.Id, region.Identifier); System.Diagnostics.Debug.WriteLine(message); } } } System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2},{3}", CrossGeofence.Id, "Location update", lastLocation.Coordinate.Latitude, lastLocation.Coordinate.Longitude)); }
public CocoaBeaconProvider(CLBeaconRegion beaconRegion) { Debug.WriteLine("constructor()", LogTag); if (!CLLocationManager.LocationServicesEnabled) { Debug.WriteLine("Location services disabled, my bad.", LogTag); return; } try { CLBeaconRegion oldRegion = new CLBeaconRegion(beaconRegion.Uuid, beaconRegion.Major.UInt16Value, beaconRegion.Minor.UInt16Value, "TPMS"); _locationManager.StopMonitoring(oldRegion); } catch (Exception) { } _locationManagerDelegate = new UniversalBeaconLocationManagerDelegate(this); _locationManager = new CLLocationManager(); _locationManager.Delegate = _locationManagerDelegate; _clBeaconRegion = beaconRegion; }
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"); }; }
public void StopBeacon() { System.Diagnostics.Debug.WriteLine("StopBeacon"); _beaconManager.StopRangingBeacons(_fieldRegion); _beaconManager.StopMonitoring(_fieldRegion); }
void RemoveRegionMonitoring() { foreach (CLRegion region in _clManager.MonitoredRegions) { _clManager.StopMonitoring(region); } }
async void Broadcast(CLLocationManager manager, CLRegion region, GeofenceState status) { try { if (region is CLCircularRegion native) { var geofence = await this.repository.Get(native.Identifier); if (geofence != null) { this.gdelegate.OnStatusChanged(status, geofence); if (geofence.SingleUse) { await this.repository.Remove(geofence.Identifier); manager.StopMonitoring(native); } } } } catch (Exception ex) { Log.Write(ex); } }
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"); }; }
public void StopMonitoringRegion(string identifier) { var region = _manager.MonitoredRegions.ToArray <CLRegion>().FirstOrDefault(r => r.Identifier.Equals(identifier)); if (_manager != null && region != null) { _manager.StopMonitoring(region); _logger?.Information($"iOS: Stopped monitoring: {identifier}"); } }
public void Stop() { foreach (var phoneNumber in _phoneNumerList) { var beaconInfo = GetBeaconInfo(phoneNumber); _locationMgr?.StopMonitoring(beaconInfo.BeaconRegion); _locationMgr?.StopRangingBeacons(beaconInfo.BeaconRegion); } _locationMgr = null; }
protected override void StopMonitoringInternal() { _locationManager.DidRangeBeacons -= LocationManager_DidRangeBeacons; _locationManager.StopUpdatingLocation(); foreach (var region in _beaconRegions) { _locationManager.StopMonitoring(region); _locationManager.StopRangingBeacons(region); } }
public void StopBeacon() { System.Diagnostics.Debug.WriteLine("StopBeacon"); _locationMgr.StopRangingBeacons(clBeaconRegion); _locationMgr.StopMonitoring(clBeaconRegion); _listOfCLBeaconRegion.Clear(); _locationMgr.DidRangeBeacons -= HandleDidRangeBeacons; _locationMgr.StopUpdatingLocation(); }
public void Stop() { foreach (var beaconRegion in _listOfCLBeaconRegion) { _locationMgr.StopRangingBeacons(beaconRegion); _locationMgr.StopMonitoring(beaconRegion); } _listOfCLBeaconRegion.Clear(); _locationMgr.DidRangeBeacons -= HandleDidRangeBeacons; _locationMgr.StopUpdatingLocation(); }
public async Task Stop() { _centralManager.StopScan(); foreach (var beaconRegion in _listOfCLBeaconRegion) { _locationMgr.StopRangingBeacons(beaconRegion); _locationMgr.StopMonitoring(beaconRegion); } _listOfCLBeaconRegion.Clear(); _locationMgr.DidRangeBeacons -= HandleDidRangeBeacons; _locationMgr.StopUpdatingLocation(); }
public void RemoveBeaconFromMonitoring(BeaconDevice beacon) { lock (_sync) { var foundBeacon = _beacons.FirstOrDefault(b => b.DeviceId == beacon.DeviceId); if (foundBeacon != null) { _beacons.Remove(foundBeacon); } var foundBeaconRegion = _locationManager.MonitoredRegions.FirstOrDefault(br => (br as CLRegion)?.Identifier == beacon.DeviceId) as CLBeaconRegion; if (foundBeaconRegion != null) { _locationManager.StopMonitoring(foundBeaconRegion); } } }
// If you turn off passive monitoring, the app cannot be launched by iOS due to // a location change. So be warned. public void StopPassiveMonitoring( ) { Console.WriteLine("LocationManager: StopPassiveMonitoring - THIS ENDS ALL LOCATION AWARENESS."); // this turns off our passive monitoring region monitoring. // Realistically, this should NEVER be called, because this is // how iOS wakes the app. // the problem with this is it works great but will cause a solid arrow, misleading users //LocationManager.StopMonitoringSignificantLocationChanges( ); foreach (TrackedRegion region in Regions) { CLLocationManager.StopMonitoring(region.Region); } }
// 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"); } } } } }
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"); }; }
void StopMonitor() { if (!isMonitoring) { return; } locationManager.StopRangingBeaconsInRegion(beaconRegion); locationManager.StopMonitoring(beaconRegion); locationManager.DidStartMonitoring -= DidStartMonitoringForRegion; locationManager.DidEnter -= DidEnterRegion; locationManager.DidExit -= DidExitRegion; locationManager.DidRangeBeacons -= DidRangeBeacons; Log("Stopped monitoring."); isMonitoring = false; }
async void Broadcast(CLLocationManager manager, CLRegion region, GeofenceState status) { if (region is CLCircularRegion native) { var geofence = await this.repository.Get(native.Identifier); if (geofence != null) { await this.delegates.Value.RunDelegates(x => x.OnStatusChanged(status, geofence)); if (geofence.SingleUse) { await this.repository.Remove(geofence.Identifier); manager.StopMonitoring(native); } } } }
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); } } }
/// <summary> /// Geofence plugin iOS implementation /// </summary> public GeofenceImplementation() { mGeofenceResults = new Dictionary <string, GeofenceResult>(); using (var pool = new NSAutoreleasePool()) { pool.InvokeOnMainThread(() => { locationManager = new CLLocationManager(); locationManager.DidStartMonitoringForRegion += DidStartMonitoringForRegion; locationManager.RegionEntered += RegionEntered; locationManager.RegionLeft += RegionLeft; locationManager.Failed += OnFailure; locationManager.DidDetermineState += DidDetermineState; locationManager.LocationsUpdated += LocationsUpdated; }); } string priorityType = "Balanced Power"; switch (CrossGeofence.GeofencePriority) { case GeofencePriority.HighAccuracy: priorityType = "High Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyBest; break; case GeofencePriority.AcceptableAccuracy: priorityType = "Acceptable Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; break; case GeofencePriority.MediumAccuracy: priorityType = "Medium Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyHundredMeters; break; case GeofencePriority.LowAccuracy: priorityType = "Low Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyKilometer; break; case GeofencePriority.LowestAccuracy: priorityType = "Lowest Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyThreeKilometers; break; default: locationManager.DesiredAccuracy = CLLocation.AccurracyBestForNavigation; break; } System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Location priority set to", priorityType)); if (CrossGeofence.SmallestDisplacement > 0) { locationManager.DistanceFilter = CrossGeofence.SmallestDisplacement; System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2} meters", CrossGeofence.Id, "Location smallest displacement set to", CrossGeofence.SmallestDisplacement)); } if (locationManager.MonitoredRegions.Count > 0 && IsMonitoring) { NSSet monitoredRegions = locationManager.MonitoredRegions; foreach (CLCircularRegion region in monitoredRegions) { //If not on regions remove on startup since that region was set not persistent if (!Regions.ContainsKey(region.Identifier)) { locationManager.StopMonitoring(region); } else { locationManager.RequestState(region); } } locationManager.StartMonitoringSignificantLocationChanges(); string message = string.Format("{0} - {1} {2} region(s)", CrossGeofence.Id, "Actually monitoring", locationManager.MonitoredRegions.Count); System.Diagnostics.Debug.WriteLine(message); } SetLastKnownLocation(locationManager.Location); }
public override void ViewDidLoad() { base.ViewDidLoad(); uuidTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; uuidTextField.InputView = new UuidPickerView(uuidTextField); uuidTextField.EditingDidBegin += HandleEditingDidBegin; uuidTextField.EditingDidEnd += (sender, e) => { uuid = new NSUuid(uuidTextField.Text); NavigationItem.RightBarButtonItem = saveButton; }; majorTextField.KeyboardType = UIKeyboardType.NumberPad; majorTextField.ReturnKeyType = UIReturnKeyType.Done; majorTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; majorTextField.EditingDidBegin += HandleEditingDidBegin; majorTextField.EditingDidEnd += (sender, e) => { major = numberFormatter.NumberFromString(majorTextField.Text); NavigationItem.RightBarButtonItem = saveButton; }; minorTextField.KeyboardType = UIKeyboardType.NumberPad; minorTextField.ReturnKeyType = UIReturnKeyType.Done; minorTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; minorTextField.EditingDidBegin += HandleEditingDidBegin; minorTextField.EditingDidEnd += (sender, e) => { minor = numberFormatter.NumberFromString(minorTextField.Text); NavigationItem.RightBarButtonItem = saveButton; }; enabledSwitch.ValueChanged += (sender, e) => { enabled = enabledSwitch.On; }; notifyOnEntrySwitch.ValueChanged += (sender, e) => { notifyOnEntry = notifyOnEntrySwitch.On; }; notifyOnExitSwitch.ValueChanged += (sender, e) => { notifyOnExit = notifyOnExitSwitch.On; }; notifyOnDisplaySwitch.ValueChanged += (sender, e) => { notifyOnDisplay = notifyOnDisplaySwitch.On; }; doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) => { uuidTextField.ResignFirstResponder(); majorTextField.ResignFirstResponder(); minorTextField.ResignFirstResponder(); TableView.ReloadData(); }); saveButton = new UIBarButtonItem(UIBarButtonSystemItem.Save, (sender, e) => { if (enabled) { var region = Helpers.CreateRegion(uuid, major, minor); if (region != null) { region.NotifyOnEntry = notifyOnEntry; region.NotifyOnExit = notifyOnExit; region.NotifyEntryStateOnDisplay = notifyOnDisplay; locationManger.StartMonitoring(region); } } else { var region = (CLBeaconRegion)locationManger.MonitoredRegions.AnyObject; if (region != null) { locationManger.StopMonitoring(region); } } NavigationController.PopViewController(true); }); NavigationItem.RightBarButtonItem = saveButton; }
public override void ViewDidUnload() { base.ViewDidUnload(); LocationManager.DidRangeBeacons -= LocationManager_DidRangeBeacons; LocationManager.StopMonitoring(BeaconRegion); }
public void StopMonitoring(GeofenceRegion region) { var native = ToNative(region); locationManager.StopMonitoring(native); }
/// <summary> /// Geofence plugin iOS implementation /// </summary> public GeofenceImplementation() { mGeofenceResults = new Dictionary<string, GeofenceResult>(); locationManager = new CLLocationManager(); locationManager.DidStartMonitoringForRegion += DidStartMonitoringForRegion; locationManager.RegionEntered += RegionEntered; locationManager.RegionLeft +=RegionLeft; locationManager.Failed += OnFailure; locationManager.DidDetermineState += DidDetermineState; locationManager.LocationsUpdated += LocationsUpdated; string priorityType = "Balanced Power"; switch(CrossGeofence.GeofencePriority) { case GeofencePriority.HighAccuracy: priorityType = "High Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyBest; break; case GeofencePriority.AcceptableAccuracy: priorityType = "Acceptable Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; break; case GeofencePriority.MediumAccuracy: priorityType = "Medium Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyHundredMeters; break; case GeofencePriority.LowAccuracy: priorityType = "Low Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyKilometer; break; case GeofencePriority.LowestAccuracy: priorityType = "Lowest Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyThreeKilometers; break; default: locationManager.DesiredAccuracy = CLLocation.AccurracyBestForNavigation; break; } System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Location priority set to", priorityType)); if(CrossGeofence.SmallestDisplacement>0) { locationManager.DistanceFilter = CrossGeofence.SmallestDisplacement; System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2} meters", CrossGeofence.Id, "Location smallest displacement set to", CrossGeofence.SmallestDisplacement)); } if (locationManager.MonitoredRegions.Count > 0 && IsMonitoring) { NSSet monitoredRegions = locationManager.MonitoredRegions; foreach (CLCircularRegion region in monitoredRegions) { //If not on regions remove on startup since that region was set not persistent if (!Regions.ContainsKey(region.Identifier)) { locationManager.StopMonitoring(region); } else { locationManager.RequestState(region); } } locationManager.StartMonitoringSignificantLocationChanges(); string message = string.Format("{0} - {1} {2} region(s)", CrossGeofence.Id, "Actually monitoring", locationManager.MonitoredRegions.Count); System.Diagnostics.Debug.WriteLine(message); } SetLastKnownLocation(locationManager.Location); }
public void StopBeacon() { _locationMgr.StopRangingBeacons(_fieldRegion); _locationMgr.StopMonitoring(_fieldRegion); _locationMgr.StopUpdatingLocation(); }
internal void RemoveRegion(CLRegion region) { _locationManager.StopMonitoring(region); }
private void StopMonitoringHome() { locationManager.StopMonitoring(HomeRegion()); }