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); }
/// <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 }
/// <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"); } if (id != _shape.Id) { // replace with correctly named CLRegion _shape = new CLCircularRegion(new CLLocationCoordinate2D(_shape.Center.Latitude, _shape.Center.Longitude), _shape.Radius, id); } #elif TIZEN _id = id; _shape = ((Geocircle)geoshape); #else throw new PlatformNotSupportedException(); #endif }
private Geofence(Windows.Devices.Geolocation.Geofencing.Geofence fence) { _fence = fence; }