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); }
//创建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); }
/// <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; } } }
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 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); }
/// <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); }
static async Task RegisterFenceAsync(double fenceRadius, MonitoredGeofenceStates monitoredStates, TimeSpan dwellTime) { // Where are we? BasicGeoposition position = await GetCurrentLocationAsync(); Geofence fence = null; // Get rid of any existing geofences. This is a bit of a TBD. The fence I'm // creating is meant to be a single-use fence so my understanding would be // that the system gets rid of it for me. Maybe the system will do that // "later" but, right now, it's still there so if I try and add a fence // with the same ID I'll get an error so I remove the original fence // myself. if (IsFenceRegistered) { fence = GeofenceMonitor.Current.Geofences.First( f => f.Id == FENCE_ID); GeofenceMonitor.Current.Geofences.Remove(fence); } fence = new Geofence( FENCE_ID, new Geocircle(position, fenceRadius), monitoredStates, false, // means it's not a single-use event dwellTime); GeofenceMonitor.Current.Geofences.Add(fence); }
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); }
static async Task InternalRegisterAsync(double fenceRadius, MonitoredGeofenceStates monitoredStates, TimeSpan dwellTime) { try { if (IsRegistered) { throw new InvalidOperationException("Already registered"); } var access = await BackgroundExecutionManager.RequestAccessAsync(); if ((access != BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity) && (access != BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)) { throw new InvalidOperationException("Bad exception but we've no access!"); } await RegisterFenceAsync(fenceRadius, monitoredStates, dwellTime); await RegisterTaskAsync(); } catch { Unregister(); throw; } }
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); }
public Geofence(string id, IGeoShape geoShape, MonitoredGeofenceStates states, bool singleUse) { this.Id = id; this.GeoShape = geoShape; this.States = states; this.SingleUse = singleUse; this.LastStatus = MonitoredGeofenceStates.Exited; }
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); }
public Geofence(string id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, bool singleUse, TimeSpan dwellTime, DateTimeOffset startTime, TimeSpan duration) { Duration = duration; DwellTime = dwellTime; Geoshape = geoshape; Id = id; MonitoredStates = monitoredStates; SingleUse = singleUse; StartTime = startTime; }
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 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 Geofence GenerateGeofence(string key, double latitude, double longitude, double altitude, double radius) { var calendar = new Windows.Globalization.Calendar(); calendar.SetToNow(); BasicGeoposition position; position.Latitude = latitude; position.Longitude = longitude; position.Altitude = altitude; 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 = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; var dwellTime = TimeSpan.FromSeconds(5); return(new Geofence(key, geocircle, mask, false, dwellTime)); }
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 void SetupGeofence() { //Set up a unique key for the geofence string GeofenceKey = "My Home Geofence1"; BasicGeoposition GeoFenceRootPosition = GetMyHomeLocation(); double Georadius = 500; // the geocircle is the circular region that defines the geofence Geocircle geocircle = new Geocircle(GeoFenceRootPosition, Georadius); bool singleUse = false; //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 = TimeSpan.FromSeconds(0); // 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 +=; //x = GeofenceMonitor.Current.LastKnownGeoposition.Coordinate.Longitude; //GeofenceMonitor.Current.GeofenceStateChanged += Current_GeofenceStateChanged; }
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); }
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; }
private Geofence GenerateGeofence() { BasicGeoposition position = new BasicGeoposition() { Altitude = 0.0, Latitude = 4.796973, Longitude = 7.032254 }; double radius = 100.0; var dwellTime = TimeSpan.FromMinutes(2); // 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 monitoredStates = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; return(new Geofence(Constants.GeofenceId, geocircle, monitoredStates, singleUse, dwellTime)); }
public Geofence(string id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, bool singleUse, TimeSpan dwellTime) : this(id, geoshape, monitoredStates, singleUse, dwellTime, new DateTimeOffset(1601, 1, 1, 0, 0, 0, TimeSpan.FromSeconds(0)), TimeSpan.FromSeconds(0)) { }
public Geofence(string id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, bool singleUse) : this(id, geoshape, monitoredStates, singleUse, TimeSpan.FromSeconds(10)) { }
private Geofence GenerateGeofence() { _rootPage.NotifyUser("", NotifyType.StatusMessage); string fenceKey = Id.Text; if (fenceKey.Length == 0) { _rootPage.NotifyUser("Name must be between 1 and 64 characters.", NotifyType.ErrorMessage); return(null); } BasicGeoposition position; double radius; if (!ParseDoubleFromTextBox(Longitude, "Longitude", -180, 180, out position.Longitude) || !ParseDoubleFromTextBox(Latitude, "Latitude", -90, 90, out position.Latitude) || !ParseDoubleFromTextBox(Radius, "Radius", .1, 10018754.3, out radius)) { return(null); } position.Altitude = 0.0; // the geofence is a circular region Geocircle geocircle = new Geocircle(position, radius); bool singleUse = SingleUse.IsChecked.Value; // want to listen for enter geofence, exit geofence and remove geofence events // you can select a subset of these event states MonitoredGeofenceStates mask = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; // Dwell time is how long you need to be in geofence to have been considered to have Entered it. TimeSpan dwellTime; if (!ParseTimeSpan(DwellTime.Text, defaultDwellTime, out dwellTime)) { _rootPage.NotifyUser("Invalid Dwell Time.", NotifyType.ErrorMessage); return(null); } // The Duration is the length of time the geofence is active. // Zero means "infinite duration". TimeSpan duration; if (!ParseTimeSpan(Duration.Text, TimeSpan.Zero, out duration)) { _rootPage.NotifyUser("Invalid Duration.", NotifyType.ErrorMessage); return(null); } // setting up the start time of the geofence DateTimeOffset startTime; if (StartImmediately.IsChecked.Value) { // The special "start immediately" value can be used if the duration is zero. // Otherwise, we get the current time as the start time. startTime = (duration == TimeSpan.Zero) ? startImmediately : DateTimeOffset.Now; } else { startTime = StartDate.Date + StartTime.Time; } // Let the platform detect other invalid parameter combinations. try { return(new Geofence(fenceKey, geocircle, mask, singleUse, dwellTime, startTime, duration)); } catch (Exception ex) { _rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage); return(null); } }
public static IAsyncAction RegisterAsync(double fenceRadius, MonitoredGeofenceStates monitoredStates, TimeSpan dwellTime) { return(InternalRegisterAsync(fenceRadius, monitoredStates, dwellTime).AsAsyncAction()); }
private async void SaveGeofenceItem() { bool success = false; if (this.IsValid()) { // Define the fence location and radius. BasicGeoposition position; position.Latitude = this.Latitude; position.Longitude = this.Longitude; position.Altitude = 0.0; // Set a circular region for the geofence. Geocircle geocircle = new Geocircle(position, this.Radius); // Set the monitored states. MonitoredGeofenceStates monitoredStates = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed; // check if there is a geo fence with same name. if yes, remove it var currGeofence = geofences.Where(gf => gf.Id == this.editingGeofenceName).FirstOrDefault(); int index = geofences.Count; if (currGeofence != null) { index = this.geofences.IndexOf(currGeofence); this.geofences.Remove(currGeofence); this.editingGeofenceName = string.Empty; } // Create the geofence. Geofence geofence = new Geofence(this.Name, geocircle, monitoredStates, false); try { // Add to geo fence monitor geofences.Insert(index, geofence); success = true; } catch (Exception) { success = false; } await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { if (success) { var dialog = new MessageDialog("Geofence saved!"); await dialog.ShowAsync(); } else { var dialog = new MessageDialog("Error saving geofence"); await dialog.ShowAsync(); } }); } }
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); }
public GeofenceBuilder ConfigureMonitoredStates(MonitoredGeofenceStates states) { _monitoredStates = states; return(this); }