public async Task AddGeofence(string id, double latitude, double longitude, int radius) { try { await _uiThreadProvider.RunInUIThread(() => { var geoCircle = new Geocircle(new BasicGeoposition { Latitude = latitude, Longitude = longitude }, radius); var geofence = new Geofence(id, geoCircle, MonitoredGeofenceStates.Entered, false); GeofenceMonitor.Current.Geofences.Add(geofence); }); } catch (Exception e) { _logService.Log(Tag, e); throw; } }
public void AddFence() { // Replace if it already exists for this maneuver key var oldFence = GeofenceMonitor.Current.Geofences.Where(p => p.Id == soort.ToString()).FirstOrDefault(); if (oldFence != null) { GeofenceMonitor.Current.Geofences.Remove(oldFence); } Geocircle geocircle = new Geocircle(Position, 25); bool singleUse = true; MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; var geofence = new Geofence(soort.ToString(), geocircle, mask, singleUse, TimeSpan.FromSeconds(1)); GeofenceMonitor.Current.Geofences.Add(geofence); fence = geofence; }
/// <summary> /// Crea un geofence. /// </summary> /// <param name="id"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <param name="radius"></param> private void NewGeofence(string id, double latitude, double longitude, double radius) { // Establecemos la posición del Geofence. var position = new BasicGeoposition { Latitude = latitude, Longitude = longitude }; // El Geofence es un círculo centrado en el punto dado por la latitud y la longitud con el radio asignado en la propiedad radius. var geocircle = new Geocircle(position, radius); // Queremos gestionar los eventos al entrar en la zona. const MonitoredGeofenceStates mask = MonitoredGeofenceStates.Entered; // Tiempo que el usuario debe estar en el área para recibir la notificación. var dwellTime = TimeSpan.FromSeconds(5); // Añadimos el Geofence al GeofenceMonitor. var geofence = new Geofence(id, geocircle, mask, false, dwellTime); if (!GeofenceMonitor.Current.Geofences.Contains(geofence)) GeofenceMonitor.Current.Geofences.Add(geofence); }
private void AddPushpin(Waypoint poi, int ID) { Pushpin pp = null; if (poi is PointOfInterest) { PointOfInterest poii = poi as PointOfInterest; pp = new Pushpin() { Tag = new InfoBoxData() { Title = poii.Name, Description = poii.Information, ImagePath = poii.ImagePath } }; pp.Background = new SolidColorBrush(Windows.UI.Colors.Red); } else { pp = new Pushpin(); pp.Background = new SolidColorBrush(Windows.UI.Colors.Blue); } MapLayer.SetPosition(pp, new Location(poi.Latitude, poi.Longitude)); pp.Tapped += PinTapped; layer.Children.Add(pp); Geocircle circle = new Geocircle(new BasicGeoposition() { Latitude = poi.Latitude, Longitude = poi.Longitude, Altitude=0 }, 15); Geofence fence = new Geofence(""+ID, circle, MonitoredGeofenceStates.Entered, false, new TimeSpan(10)); GeofenceMonitor.Current.Geofences.Add(fence); }
private void SetupGeofence() { //Set up a unique key for the geofence string GeofenceKey = "My Home Geofence"; BasicGeoposition GeoFenceRootPosition = GetMyHomeLocation(); double Georadius = 500; // the geocircle is the circular region that defines the geofence Geocircle geocircle = new Geocircle(GeoFenceRootPosition, Georadius); bool singleUse = (bool)SingleUse.IsChecked; //Selecting a subset of the events we need to interact with the geofence MonitoredGeofenceStates GeoFenceStates = 0; GeoFenceStates |= MonitoredGeofenceStates.Entered; GeoFenceStates |= MonitoredGeofenceStates.Exited; // setting up how long you need to be in geofence for enter event to fire TimeSpan dwellTime; dwellTime = DwellTime.Text!=""? ParseTimeSpan(DwellTime.Text) : TimeSpan.FromSeconds(DefaultDwellTimeInSeconds); // setting up how long the geofence should be active TimeSpan GeoFenceDuration; GeoFenceDuration = TimeSpan.FromDays(10); // setting up the start time of the geofence DateTimeOffset GeoFenceStartTime = DateTimeOffset.Now; geofence = new Geofence(GeofenceKey, geocircle, GeoFenceStates, singleUse, dwellTime, GeoFenceStartTime, GeoFenceDuration); //Add the geofence to the GeofenceMonitor GeofenceMonitor.Current.Geofences.Add(geofence); //GeofenceMonitor.Current.GeofenceStateChanged += Current_GeofenceStateChanged; }
/// <summary> /// Create geo fence around certain geopoint with a given radius /// </summary> /// <param name="fenceKey">The key of the fence</param> /// <param name="latitude">Latitude of the geo fence</param> /// <param name="longitude">Longitude of the geo fence</param> /// <param name="radius">Radius of the geo fence</param> /// <param name="fenceColor">UI color of the geo fence</param> private void CreateGeofence( string fenceKey, double latitude, double longitude, double radius, Color fenceColor ) { if( GeofenceMonitor.Current.Geofences.All( v => v.Id != fenceKey ) ) { var position = new BasicGeoposition { Latitude = latitude, Longitude = longitude, Altitude = 0.0 }; CreateCircle( position, radius, fenceColor ); // The geofence is a circular region var geocircle = new Geocircle( position, radius ); // Listen for enter geofence and exit geofence events MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; var geofence = new Geofence( fenceKey, geocircle, mask, false ); GeofenceMonitor.Current.Geofences.Add( geofence ); GeofenceMonitor.Current.StatusChanged += GeoFence_StatusChanged; } else { foreach( var f in GeofenceMonitor.Current.Geofences.Where( f => f.Id == fenceKey ) ) { var x = f.Geoshape as Geocircle; if( x != null ) { CreateCircle( x.Center, x.Radius, fenceColor ); } break; } } }
/// <summary> /// Loads the content for the second pivot item when it is scrolled into view. Second pivot is named "cars" /// </summary> private async void SecondPivot_Loaded(object sender, RoutedEventArgs e) { var sampleDataGroup = await SampleDataSource.GetGroupAsync("PointsOfInterest-1"); this.DefaultViewModel[SecondGroupName] = sampleDataGroup; initFences(); foreach (SampleDataItem gasStationItem in ((SampleDataGroup)DefaultViewModel[FirstGroupName]).Items) { MapIcon gasStationIcon = new MapIcon(); gasStationIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/map.categories.petrolstation.tier20.png")); gasStationIcon.NormalizedAnchorPoint = new Point(0.5, 0.5); gasStationIcon.Location = gasStationItem.Location; gasStationIcon.Title = gasStationItem.Title; gasStationIcon.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible; this.map.MapElements.Add(gasStationIcon); Geocircle gasStationFence = new Geocircle(gasStationItem.Location.Position, 250.0); addFence(gasStationItem.UniqueId, gasStationFence); updateGasStationFence(gasStationItem.UniqueId, gasStationFence, Windows.UI.Colors.Blue); } if (!double.IsNaN(zoomLevel)) { await this.map.TrySetViewAsync(new Geopoint(center), zoomLevel); } else { await this.map.TrySetViewBoundsAsync(sampleDataGroup.BestMapViewBoxList, null, Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None); } }
private void CreateGeofence() { Geofence geofence = null; string fenceKey = "Test"; BasicGeoposition position; position.Latitude = 35.246166; position.Longitude = 33.035971; position.Altitude = 0.0; // 35.246166, 33.035971 // the geofence is a circular region Geocircle geocircle = new Geocircle(position, 50); // want to listen for enter geofence, exit geofence and remove geofence events // you can select a subset of these event states MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; mask |= MonitoredGeofenceStates.Removed; geofence = new Geofence(fenceKey, geocircle, mask, false); GeofenceMonitor.Current.Geofences.Add(geofence); }
//创建Geofence public bool CreateGeofence(string id, double lat, double lon, double radius, GeofenceStateChangedCallback callback) { if (GeofenceMonitor.Current.Geofences.SingleOrDefault(g => g.Id == id) != null) { return(false); } var position = new BasicGeoposition(); position.Latitude = lat; position.Longitude = lon; var geocircle = new Geocircle(position, radius); MonitoredGeofenceStates mask = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited; // Create Geofence with the supplied id, geocircle and mask, not for single use // and with a dwell time of 1 seconds var geofence = new Geofence(id, geocircle, mask, false, new TimeSpan(0, 0, 1)); GeofenceMonitor.Current.Geofences.Add(geofence); //将回调函数存入geofencesStateChangedCallback if (callbacks.ContainsKey(GetGeofenceIndex(geofence))) { callbacks.Remove(GetGeofenceIndex(geofence)); } callbacks.Add(GetGeofenceIndex(geofence), callback); //注册Geofence状态改变回调事件 GeofenceMonitor.Current.GeofenceStateChanged -= Current_GeofenceStateChanged; GeofenceMonitor.Current.GeofenceStateChanged += Current_GeofenceStateChanged; return(true); }
private void AddPushpin(Waypoint poi, int ID) { Pushpin pp = null; if (poi is PointOfInterest) { PointOfInterest poii = poi as PointOfInterest; pp = new Pushpin() { Tag = new InfoBoxData() { Title = poii.Name, Description = poii.Information, ImagePath = poii.ImagePath } }; pp.Background = new SolidColorBrush(Windows.UI.Colors.Red); } else { pp = new Pushpin(); pp.Background = new SolidColorBrush(Windows.UI.Colors.Blue); } MapLayer.SetPosition(pp, new Location(poi.Latitude, poi.Longitude)); pp.Tapped += PinTapped; layer.Children.Add(pp); Geocircle circle = new Geocircle(new BasicGeoposition() { Latitude = poi.Latitude, Longitude = poi.Longitude, Altitude = 0 }, 15); Geofence fence = new Geofence("" + ID, circle, MonitoredGeofenceStates.Entered, false, new TimeSpan(10)); GeofenceMonitor.Current.Geofences.Add(fence); }
private void Add_Click(object sender, RoutedEventArgs e) { Geofence geofence; string id = this.tBoxName.Text; BasicGeoposition position; position.Latitude = Double.Parse(this.tBoxLatitude.Text); position.Longitude = Double.Parse(this.tBoxLongitude.Text); position.Altitude = 0.0; double radius = Double.Parse(this.tBoxRadius.Text); // the geofence is a circular region Geocircle geocircle = new Geocircle(position, radius); // want to listen for enter geofence, exit geofence and remove geofence events // you can select a subset of these event states MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; mask |= MonitoredGeofenceStates.Removed; TimeSpan dwellTime = new TimeSpan(0); geofence = new Geofence(id, geocircle, mask, false, dwellTime); this.geoservice.AddGeofence(geofence); }
public void AddRegion(GeofenceCircularRegion region) { if (string.IsNullOrEmpty(region.Id)) { return; } RemoveRegion(region.Id); var position = new BasicGeoposition(); position.Latitude = region.Latitude; position.Longitude = region.Longitude; var geocircle = new Geocircle(position, region.Radius); Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates mask = 0; if (region.NotifyOnEntry) { mask |= Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates.Entered; } if (region.NotifyOnExit) { mask |= Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates.Exited; } var geofence = new Windows.Devices.Geolocation.Geofencing.Geofence(region.Id, geocircle, mask, false, new TimeSpan(0, 0, CrossGeofence.StayedInDuration / 1000), DateTime.Now, TimeSpan.MaxValue); Windows.Devices.Geolocation.Geofencing.GeofenceMonitor.Current.Geofences.Add(geofence); GeofenceStore.SharedInstance.Save(region); }
public void AddRegion(GeofenceCircularRegion region) { if (string.IsNullOrEmpty(region.Id)) return; RemoveRegion(region.Id); var position = new BasicGeoposition(); position.Latitude = region.Latitude; position.Longitude = region.Longitude; var geocircle = new Geocircle(position, region.Radius); Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates mask = 0; if (region.NotifyOnEntry) { mask |= Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates.Entered; } if (region.NotifyOnExit) { mask |= Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates.Exited; } var geofence = new Windows.Devices.Geolocation.Geofencing.Geofence(region.Id, geocircle, mask, false, new TimeSpan(0, 0, CrossGeofence.StayedInDuration / 1000), DateTime.Now, TimeSpan.MaxValue); Windows.Devices.Geolocation.Geofencing.GeofenceMonitor.Current.Geofences.Add(geofence); GeofenceStore.SharedInstance.Save(region); }
private void AddGeofenceHere_Click(object sender, RoutedEventArgs e) { ClearStatus(); try { double radiusInMeters = Settings.GeofenceRadiusMeters; ShowStatus("Adding geofence..."); var geofences = GeofenceMonitor.Current.Geofences; var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"); BasicGeoposition position; position.Altitude = 0; position.Latitude = _geoposition.Coordinate.Point.Position.Latitude; position.Longitude = _geoposition.Coordinate.Point.Position.Longitude; var geocircle = new Geocircle(position, radiusInMeters); var geofence = new Geofence(timestamp, geocircle); geofences.Add(geofence); Logger.Trace(TraceLevel.Info, String.Format("Added geofence for current location: {0} radius: {1} meters, id {2}", Logger.FormatLatLong(position.Latitude, position.Longitude), radiusInMeters, timestamp)); // Re-center the map since the user wanted a geofence at the current location Map.SetView(new Bing.Maps.Location(position.Latitude, position.Longitude)); GetGeofences_Click(this, null); } catch (Exception ex) { Logger.Trace(TraceLevel.Error, "Error adding geofence for current location: " + Logger.FormatException(ex)); ShowStatus("Could not add geofence for current location: " + ex.Message); } }
public static void CreateGeofence(string id, double lat, double lon, double radius) { if (GeofenceMonitor.Current.Geofences.SingleOrDefault(g => g.Id == id) != null) { return; } var position = new BasicGeoposition(); position.Latitude = lat; position.Longitude = lon; var geocircle = new Geocircle(position, radius); MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; // Uncomment these to monitor other states mask |= MonitoredGeofenceStates.Exited; mask |= MonitoredGeofenceStates.Removed; // Create Geofence with the supplied id, geocircle and mask, not for single use // and with a dwell time of 5 seconds //MessageBox.Show(string.Format("Geofence {0} created!", id.ToString())); var geofence = new Geofence(id, geocircle, mask, false, new TimeSpan(0, 0, 5)); GeofenceMonitor.Current.Geofences.Add(geofence); }
/// <summary> /// This method creates a Geofence for a given Shoppinglist. /// </summary> /// <param name="shop">Object for which a Geofence should be created.</param> private Geofence CreateGeofence(Shop shop) { Geocircle circle = new Geocircle((BasicGeoposition)shop.Location, (shop.Radius * 1000)); //Selecting a subset of the events we need to interact with the geofence const MonitoredGeofenceStates geoFenceStates = MonitoredGeofenceStates.Entered; // Setting up how long you need to be in geofence for enter event to fire TimeSpan dwellTime = TimeSpan.FromSeconds(1); // Setting up how long the geofence should be active TimeSpan geoFenceDuration = TimeSpan.FromSeconds(0); // Setting up the start time of the geofence DateTimeOffset geoFenceStartTime = DateTimeOffset.Now; // Create object Geofence fence = new Geofence (shop.ID, circle, geoFenceStates, false, dwellTime, geoFenceStartTime, geoFenceDuration); return(fence); }
public Geofence CreateGeofence(string fenceID, double latitude, double longitude, double altitude, double radius, bool singleUse, int dwellTime, int duration) { _fenceId = fenceID; // Define the fence location and radius. BasicGeoposition position; position.Latitude = latitude; position.Longitude = longitude; position.Altitude = altitude; _radius = radius; // in meters // Set the circular region for geofence. _geocircle = new Geocircle(position, radius); // Remove the geofence after the first trigger. _singleUse = singleUse; // Set the monitored states. _monitoredStates = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; // Set how long you need to be in geofence for the enter event to fire. _dwellTime = TimeSpan.FromSeconds(dwellTime); // Set how long the geofence should be active. _duration = TimeSpan.FromDays(duration); // Set up the start time of the geofence. _startTime = DateTime.Now; // Create the geofence. _geofence = new Geofence(_fenceId, _geocircle, _monitoredStates, _singleUse, _dwellTime, _startTime, _duration); return(_geofence); }
private Geofence CreatGeofence(BasicGeoposition position) { string fenceId = "fence"; // Define the fence location and radius. //BasicGeoposition position; //position.Latitude = 47.6510; //position.Longitude = -122.3473; //position.Altitude = 0.0; double radius = 100000; // in meters // Set the circular region for geofence. Geocircle geocircle = new Geocircle(position, radius); // Remove the geofence after the first trigger. bool singleUse = true; // Set the monitored states. MonitoredGeofenceStates monitoredStates = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; // Set how long you need to be in geofence for the enter event to fire. TimeSpan dwellTime = TimeSpan.FromMinutes(1); // Set how long the geofence should be active. TimeSpan duration = TimeSpan.FromDays(1); // Set up the start time of the geofence. DateTimeOffset startTime = DateTime.Now; // Create the geofence. Geofence geofence = new Geofence(fenceId, geocircle, monitoredStates, singleUse, dwellTime, startTime, duration); return(geofence); }
/// <summary> /// Create a geo-fence around certain geopoint with a given radius /// </summary> /// <param name="fenceKey"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <param name="radius"></param> private void CreateGeofence(string fenceKey, double latitude, double longitude, double radius, Color fenceColor) { if (GeofenceMonitor.Current.Geofences.All(v => v.Id != fenceKey)) { var position = new BasicGeoposition { Latitude = latitude, Longitude = longitude, Altitude = 0.0 }; CreateCircle(position, radius, fenceColor); // the geofence is a circular region var geocircle = new Geocircle(position, radius); // Listen for enter geofence and exit geofence events MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; var geofence = new Geofence(fenceKey, geocircle, mask, false); GeofenceMonitor.Current.Geofences.Add(geofence); GeofenceMonitor.Current.StatusChanged += EnterFence; } else { foreach (var f in GeofenceMonitor.Current.Geofences.Where(f => f.Id == fenceKey)) { var x = f.Geoshape as Geocircle; if (x != null) { CreateCircle(x.Center, x.Radius, fenceColor); } break; } } }
/// <summary> /// Invoked when the user clicks on the UI button to add a geofence. /// </summary> /// <param name="sender"></param> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> private void addFence(string uniqueId, Geocircle geoCircle) { try { string geofenceId = uniqueId; //STEP 4: Create the geofences using constructors //Basic constructor. Monitored states will be both Entered and Exited. geofenceId = uniqueId + "WithDefaults"; Geofence geofenceBasic = new Geofence(geofenceId, geoCircle); //Constructor to indicate single use or permanent geofenceId = uniqueId + "WithSingleUse"; Boolean useOnce = true; Geofence geofenceSingleUse = new Geofence(geofenceId, geoCircle, MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Removed, useOnce); //Constructor to indicate no-single use and dwell time options geofenceId = uniqueId; useOnce = false; TimeSpan stayDuration = new TimeSpan(); stayDuration = TimeSpan.FromSeconds(1); Geofence geofenceWithDuration = new Geofence(geofenceId, geoCircle, MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited, useOnce, stayDuration); //Constructor to indicate no-single use, dwell time and validity period options geofenceId = uniqueId + "WithValidityPeriodAndDwellTime3s"; useOnce = false; stayDuration = TimeSpan.FromSeconds(3); DateTime today = DateTime.Now; DateTimeOffset validFrom = today; TimeSpan validFor = new TimeSpan(0, 2, 0); Geofence geofenceWithValidityPeriod = new Geofence(geofenceId, geoCircle, MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited, useOnce, stayDuration, validFrom, validFor); // STEP 5: Add the geofences to the GeofenceMonitor //GeofenceMonitor.Current.Geofences.Add(geofenceBasic); //GeofenceMonitor.Current.Geofences.Add(geofenceSingleUse); GeofenceMonitor.Current.Geofences.Add(geofenceWithDuration); //GeofenceMonitor.Current.Geofences.Add(geofenceWithValidityPeriod); } catch (UnauthorizedAccessException) { // The user has not granted Location permission to this application // Throw an error and pop the user to enable Location Debug.WriteLine("Error: Location is not enabled or not allowed for this app. Please check the location status under: settings -> location"); } catch (Exception ex) { // GeofenceMonitor failed in adding a geofence // exceptions could be from out of memory, lat/long out of range, // too long a name, not a unique name // Error will need to be handled depending on the case Debug.WriteLine("Error:" + ex.ToString()); } }
public async void CreateGeofence() { geofencecount++; Geofence geofence = null; string fenceKey = "Safer" + geofencecount.ToString(); Geolocator MyGeolocator = new Geolocator(); Geoposition MyGeoposition = await MyGeolocator.GetGeopositionAsync(); BasicGeoposition position; position.Latitude = Double.Parse(MyGeoposition.Coordinate.Latitude.ToString()); position.Longitude = Double.Parse(MyGeoposition.Coordinate.Longitude.ToString()); position.Altitude = 0.0; double radius = 10; // the geofence is a circular region Geocircle geocircle = new Geocircle(position, radius); bool singleUse = false; // want to listen for enter geofence, exit geofence and remove geofence events // you can select a subset of these event states MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; // setting up how long you need to be in geofence for enter event to fire TimeSpan dwellTime; dwellTime = new TimeSpan(0, 0, 10);//(ParseTimeSpan("0", defaultDwellTimeSeconds)); // setting up how long the geofence should be active TimeSpan duration; duration = new TimeSpan(2, 0, 0, 0); // setting up the start time of the geofence DateTimeOffset startTime; startTime = DateTime.Today; geofence = new Geofence(fenceKey, geocircle, mask, singleUse, dwellTime, startTime, duration); GeofenceMonitor.Current.Geofences.Add(geofence); }
// add geofence to listbox private void AddGeofenceToRegisteredGeofenceListBox(Geofence geofence) { Geocircle circle = (Geocircle)geofence.Geoshape; string text = $"{geofence.Id} ({circle.Center.Latitude:0.###}, {circle.Center.Longitude:0.###}, {circle.Radius:0.#})"; RegisteredGeofenceListBox.Items.Insert(0, new ListBoxItem { Content = text, Tag = geofence }); }
public GeofenceBuilder ThenSetGeocircle(IGeoshape geocricle) { if (geocricle.GeoshapeType != GeoshapeType.Geocircle) { throw new ArgumentException($"{nameof(GeofenceBuilder)} can use only {nameof(Geocircle)} as {nameof(IGeoshape)}"); } _geoshape = geocricle as Geocircle; return(this); }
public void MakeNewGeofence(int radius) { Geocircle circle = new Geocircle(position, radius); MonitoredGeofenceStates monitoredStates = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; TimeSpan dwellTime = TimeSpan.FromSeconds(1); geofenceRadius = radius; geofence = new Geofence(name, circle, monitoredStates, false, dwellTime); }
public ZonaPerigosa(String Nome, double Raio, double Latitude, double Longitude) { this.Nome = Nome; var position = new BasicGeoposition(); position.Latitude = Latitude; position.Longitude = Longitude; position.Altitude = 0; var point = new Geopoint(position); circulo = new Geocircle(position, Raio); }
private Geofence GenerateGeofence(BasicGeoposition position, double radius, string geofenceName) { string geofenceId = geofenceName; // the geofence is a circular region: Geocircle geocircle = new Geocircle(position, radius); bool singleUse = false; MonitoredGeofenceStates mask = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited; TimeSpan dwellTime = new TimeSpan(0, 0, 1); return(new Geofence(geofenceId, geocircle, mask, singleUse, dwellTime)); }
public Geofence BuildFromAlarm(Alarm alarm) { var geoposition = new BasicGeoposition { Latitude = alarm.Latitude, Longitude = alarm.Longitude, Altitude = alarm.Altitude }; var dwellTime = TimeSpan.FromSeconds(2); var geoshape = new Geocircle(geoposition, alarm.Radius); return(new Geofence(alarm.Name, geoshape, MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited, string.IsNullOrEmpty(alarm.ActiveDays), dwellTime, DateTimeOffset.Now, TimeSpan.Zero)); }
private void AddGeofence(Geopoint location, string title, double radius) { string fenceKey = title; // the geofence is a circular region: Geocircle geocircle = new Geocircle(location.Position, radius); try { geofences.Add(new Geofence(fenceKey, geocircle, MonitoredGeofenceStates.Entered, false, TimeSpan.FromSeconds(0.1))); } catch (Exception e) { Debug.WriteLine("catched" + e); } }
private void UpdateGeofence(string fenceId, double latitude, double longitude) { var geofence = GeofenceMonitor.Current.Geofences.SingleOrDefault(f => f.Id == fenceId); if (geofence != null) GeofenceMonitor.Current.Geofences.Remove(geofence); var position = new BasicGeoposition(); position.Latitude = latitude; position.Longitude = longitude; var area = new Geocircle(position, HomeRadiusInMeters); geofence = new Geofence(fenceId, area); GeofenceMonitor.Current.Geofences.Add(geofence); }
async void loader_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (String.Equals(e.PropertyName, "ArmedFences") || String.Equals(e.PropertyName, "TriggerFence")) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { List <Geofence> result = loader.ArmedFences; // Add application fences MapShapeLayer fences = new MapShapeLayer(); MapLayer pushpins = new MapLayer(); foreach (Geofence f in result) { Geocircle c1 = f.Geoshape as Geocircle; MapPolyline fence = new MapPolyline(); fence.Color = Colors.Red; fence.Width = 5; fence.Locations = DrawMapsCircle(c1.Center, c1.Radius); fences.Shapes.Add(fence); Pushpin p = new Pushpin(); p.Background = new SolidColorBrush(Colors.Red); ToolTipService.SetToolTip(p, f.Id); MapLayer.SetPosition(p, new Location(c1.Center.Latitude, c1.Center.Longitude)); pushpins.Children.Add(p); } // Add trigger fence Geocircle c2 = loader.TriggerFence.Geoshape as Geocircle; MapPolyline trigger = new MapPolyline(); trigger.Color = Colors.Gray; trigger.Width = 5; trigger.Locations = DrawMapsCircle(c2.Center, c2.Radius); fences.Shapes.Add(trigger); myMap.ShapeLayers.Clear(); myMap.ShapeLayers.Add(fences); // Clear existing pushpins var existingLayers = myMap.Children.Where(c => c is MapLayer).ToArray(); for (int i = 0; i < existingLayers.Count(); i++) { myMap.Children.Remove(existingLayers[i]); } myMap.Children.Add(pushpins); }); } }
/// <summary> /// Initializes a new Geofence object given the id and the shape of the geofence. /// </summary> /// <param name="id"></param> /// <param name="geoshape"></param> public Geofence(string id, IGeoshape geoshape) { #if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE _fence = new Windows.Devices.Geolocation.Geofencing.Geofence(id, (Windows.Devices.Geolocation.Geocircle)((Geocircle)geoshape)); #elif __UNIFIED__ _shape = (Geocircle)geoshape; if(_shape.Radius > GeofenceMonitor.Current.maxRegion) { throw new PlatformNotSupportedException("Geofence Radius is greater than the maximum supported on this platform"); } _region = new CLCircularRegion(new CLLocationCoordinate2D(_shape.Center.Latitude, _shape.Center.Longitude), _shape.Radius, id); #else throw new PlatformNotSupportedException(); #endif }
Geofence ToNative(GeofenceRegion region) { var position = new BasicGeoposition { Latitude = region.Center.Latitude, Longitude = region.Center.Longitude }; var circle = new Geocircle(position, region.Radius.TotalMeters); var geofence = new Geofence( region.Identifier, circle, ToStates(region), region.SingleUse ); return(geofence); }
void RebuildListOfFences() { List <string> items = new List <string>(); foreach (var fence in GeofenceMonitor.Current.Geofences) { Geocircle circle = (Geocircle)fence.Geoshape; items.Add( string.Format("Fence [{0}] at [{1},{2}] radius [{3}km]", fence.Id, circle.Center.Latitude, circle.Center.Longitude, circle.Radius / 1000.0)); } this.listFences.ItemsSource = items; }
async private void ApplicationHostPage_Loaded(object sender, RoutedEventArgs e) { if (App.State.UserProfile == null) { root_frame.Navigate(typeof(UserIntroPage)); } else { var access_status = await Geolocator.RequestAccessAsync(); switch (access_status) { case GeolocationAccessStatus.Allowed: root_frame.Navigate(typeof(LandingPage)); CurrentLocation = await _geolocator.GetGeopositionAsync(); GeoLocationChanged?.Invoke(CurrentLocation.Coordinate.Point); var fence_id = App.State.NextEvent.EventID.ToString(); var fences = GeofenceMonitor.Current.Geofences; var fence = fences.Where(i => i.Id == fence_id).FirstOrDefault(); if (fence == null) { Geocircle event_radius = new Geocircle(new BasicGeoposition { Latitude = App.State.NextEvent.Latitude.Value, Longitude = App.State.NextEvent.Longitude.Value, }, 100); fence = new Geofence(fence_id, event_radius); //add a geofence GeofenceMonitor.Current.Geofences.Add(fence); } break; case GeolocationAccessStatus.Denied: root_frame.Navigate(typeof(NoLocationPage)); break; case GeolocationAccessStatus.Unspecified: break; } } }
private void updateGasStationFence(string uniqueId, Geocircle gasStationFence, Color fillColor) { if (gasStationFenceDictionary.ContainsKey(uniqueId)) { this.map.MapElements.Remove(gasStationFenceDictionary[uniqueId]); gasStationFenceDictionary.Remove(uniqueId); } MapPolygon gasStationPolygon = new MapPolygon(); gasStationPolygon.Path = gasStationFence.ToGeopath(); fillColor.A = 50; gasStationPolygon.FillColor = fillColor; gasStationPolygon.StrokeThickness = 0; gasStationFenceDictionary.Add(uniqueId, gasStationPolygon); this.map.MapElements.Add(gasStationPolygon); }
public Geofence AddGeofence( String fenceId, BasicGeoposition fenceCenter, Double radiusInMeters) { if (String.IsNullOrWhiteSpace(fenceId)) { throw new ArgumentException("A fence id is required.", "fenceId"); } if (fenceId.Length > 64) { throw new ArgumentException("The fence id must be <= 64 chars.", "fenceId"); } var fenceCircle = new Geocircle(fenceCenter, radiusInMeters); // Default (omitted in ctor) = Entered/Exited const MonitoredGeofenceStates states = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; // Create the fence with the desired states and not single-use var fence = new Geofence(fenceId, fenceCircle, states, false); GeofenceMonitor.Current.Geofences.Add(fence); return(fence); // MORE EXPLICIT GEOFENCE OPTIONS // Default (omitted in ctor) = false // var isSingleUse = false; // Default (omitted in ctor) = 10 seconds // var dwellingTime = TimeSpan.FromSeconds(10); // Default (omitted in ctor) = immediate // var monitoringStartTime = DateTimeOffset.Now; // Default (omitted in ctor) = 0 seconds/indefinite // var monitoringDuration = TimeSpan.Zero; //var fence = new Geofence(fenceId, fenceCircle, states, isSingleUse, dwellingTime, monitoringStartTime, monitoringDuration); }
public static async Task TryCreateGeofence() { await Initialize(); string fenceKey = "TIG.Todo"; Geofence geofence = null; BasicGeoposition position; position.Latitude = currentLocation.Coordinate.Point.Position.Latitude; position.Longitude = currentLocation.Coordinate.Point.Position.Longitude; position.Altitude = 0.0; double radius = 100; //Suggested >50 // the geofence is a circular region Geocircle geocircle = new Geocircle(position, radius); bool singleUse = true; // want to listen for enter geofence, exit geofence and remove geofence events // you can select a subset of these event states MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; mask |= MonitoredGeofenceStates.Removed; // setting up how long you need to be in geofence for enter event to fire //TimeSpan dwellTime = TimeSpan.FromMinutes(1); TimeSpan dwellTime = TimeSpan.FromSeconds(1); // setting up how long the geofence should be active //TimeSpan duration = TimeSpan.FromHours(24); TimeSpan duration = TimeSpan.FromMinutes(2); // setting up the start time of the geofence DateTimeOffset startTime = DateTimeOffset.Now; geofence = new Geofence(fenceKey, geocircle, mask, singleUse, dwellTime, startTime, duration); GeofenceMonitor.Current.Geofences.Add(geofence); }
private void UpdateGeofence(string fenceId, double latitude, double longitude) { var geofence = GeofenceMonitor.Current.Geofences.SingleOrDefault(f => f.Id == fenceId); if (geofence != null) { GeofenceMonitor.Current.Geofences.Remove(geofence); } var position = new BasicGeoposition(); position.Latitude = latitude; position.Longitude = longitude; var area = new Geocircle(position, HomeRadiusInMeters); geofence = new Geofence(fenceId, area); GeofenceMonitor.Current.Geofences.Add(geofence); }
private void RefreshControlsFromGeofence(Geofence geofence) { Id.Text = geofence.Id; Geocircle circle = (Geocircle)geofence.Geoshape; Latitude.Text = circle.Center.Latitude.ToString(); Longitude.Text = circle.Center.Longitude.ToString(); Radius.Text = circle.Radius.ToString(); SingleUse.IsChecked = geofence.SingleUse; if (geofence.DwellTime != TimeSpan.Zero) { DwellTime.Text = geofence.DwellTime.ToString(timeSpanFormat); } else { DwellTime.Text = ""; } if (geofence.Duration != TimeSpan.Zero) { Duration.Text = geofence.Duration.ToString(timeSpanFormat); } else { Duration.Text = ""; } if (geofence.StartTime == startImmediately) { StartImmediately.IsChecked = true; } else { StartAtSpecificTime.IsChecked = true; StartDate.Date = geofence.StartTime.Date; StartTime.Time = geofence.StartTime.TimeOfDay; } }
private static void AddFence(string key, Geopoint position) { var oldFence = GeofenceMonitor.Current.Geofences.FirstOrDefault(p => p.Id == key); if (oldFence != null) { GeofenceMonitor.Current.Geofences.Remove(oldFence); } //TODO: ler raio var geocircle = new Geocircle(position.Position, 150); const bool singleUse = false; MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; //TODO: aumentar o tempo do trigger var geofence = new Geofence(key, geocircle, mask, singleUse, TimeSpan.FromSeconds(1)); GeofenceMonitor.Current.Geofences.Add(geofence); }
private async void CreateGeofence() { GeofenceMonitor.Current.Geofences.Clear(); BasicGeoposition basicGeoposition = new BasicGeoposition(); Geoposition geoposition = await geolocator.GetGeopositionAsync(); Geofence geofence; basicGeoposition.Latitude = geoposition.Coordinate.Latitude; basicGeoposition.Longitude = geoposition.Coordinate.Longitude; basicGeoposition.Altitude = (double) geoposition.Coordinate.Altitude; double radius = 10.0; Geocircle geocircle = new Geocircle(basicGeoposition, radius); // want to listen for enter geofence, exit geofence and remove geofence events // you can select a subset of these event states MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; mask |= MonitoredGeofenceStates.Removed; // setting up how long you need to be in geofence for enter event to fire TimeSpan dwellTime = new TimeSpan(1, 0, 0); // setting up how long the geofence should be active TimeSpan duration = new TimeSpan(0,10,0); // setting up the start time of the geofence DateTimeOffset startTime = DateTimeOffset.Now; geofence = new Geofence("Test", geocircle, mask, true); GeofenceMonitor.Current.Geofences.Add(geofence); }
private Geofence GenerateGeofence() { Geofence geofence = null; string fenceKey = new string(Id.Text.ToCharArray()); BasicGeoposition position; position.Latitude = Double.Parse(Latitude.Text); position.Longitude = Double.Parse(Longitude.Text); position.Altitude = 0.0; double radius = Double.Parse(Radius.Text); // the geofence is a circular region Geocircle geocircle = new Geocircle(position, radius); bool singleUse = (bool)SingleUse.IsChecked; // want to listen for enter geofence, exit geofence and remove geofence events // you can select a subset of these event states MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; mask |= MonitoredGeofenceStates.Exited; mask |= MonitoredGeofenceStates.Removed; // setting up how long you need to be in geofence for enter event to fire TimeSpan dwellTime; if ("" != DwellTime.Text) { dwellTime = new TimeSpan(ParseTimeSpan(DwellTime.Text, defaultDwellTimeSeconds)); } else { dwellTime = new TimeSpan(ParseTimeSpan("0", defaultDwellTimeSeconds)); } // setting up how long the geofence should be active TimeSpan duration; if ("" != Duration.Text) { duration = new TimeSpan(ParseTimeSpan(Duration.Text, 0)); } else { duration = new TimeSpan(ParseTimeSpan("0", 0)); } // setting up the start time of the geofence DateTimeOffset startTime; try { if ("" != StartTime.Text) { startTime = DateTimeOffset.Parse(StartTime.Text); } else { // if you don't set start time in C# the start time defaults to 1/1/1601 calendar.SetToNow(); startTime = calendar.GetDateTime(); } } catch (ArgumentNullException) { } catch (FormatException) { rootPage.NotifyUser("Start Time is not a valid string representation of a date and time", NotifyType.ErrorMessage); } catch (ArgumentException) { rootPage.NotifyUser("The offset is greater than 14 hours or less than -14 hours.", NotifyType.ErrorMessage); } geofence = new Geofence(fenceKey, geocircle, mask, singleUse, dwellTime, startTime, duration); return geofence; }
/* / Voor het toevoegen van icon's aan de map. */ private void AddMapIcon(LocationData location) { MapIcon MapIcon1 = new MapIcon(); MapIcon1.Location = new Geopoint(location.position); MapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0); MapIcon1.Title = location.name; InputMap.MapElements.Add(MapIcon1); // Geofence BasicGeoposition pos = new BasicGeoposition(); pos.Latitude = location.position.Latitude; pos.Longitude = location.position.Longitude; Geocircle circle = new Geocircle(pos, 35); MonitoredGeofenceStates monitoredStates = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; TimeSpan dwellTime = TimeSpan.FromSeconds(1); var geofence = new Windows.Devices.Geolocation.Geofencing.Geofence(location.name, circle, monitoredStates, false, dwellTime); GeofenceMonitor.Current.Geofences.Add(geofence); drawGeofence(location, 35); }