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);
      }
示例#2
0
        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);
        }
示例#3
0
        /// <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
        }
示例#4
0
        /// <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
        }
示例#5
0
 private Geofence(Windows.Devices.Geolocation.Geofencing.Geofence fence)
 {
     _fence = fence;
 }
示例#6
0
 private Geofence(Windows.Devices.Geolocation.Geofencing.Geofence fence)
 {
     _fence = fence;
 }