Geofence Geofence Geofence Geofence Class

Contains the functionality to define a geofence (a geographical area of interest) to monitor.

Syntax

Declaration

public sealed class Geofencepublic sealed class GeofencePublic NotInheritable Class Geofence

Constructors summary

Initializes a new Geofence object given the id and the shape of the geofence.

Initializes a new Geofence object given the id, the shape of the geofence, the states to monitor the geofence for, and the singleUse flag.

Initializes a new Geofence object given the id, the shape of the geofence, the states to monitor the geofence for, the singleUse flag, and the dwellTime for the geofence.

Initializes a new Geofence object given the id, the shape of the geofence, the states to monitor the geofence for, the singleUse flag, the dwellTime for the geofence, the time to start monitoring the geofence, and the duration of the geofence.

Properties summary

Gets the time window, beginning after the StartTime, during which the Geofence is monitored.

The minimum time that a position has to be inside or outside of the Geofence in order for the notification to be triggered.

The shape of the geofence region.

The id of the Geofence.

Indicates the states that the Geofence is being monitored for.

Indicates whether the Geofence should be triggered once or multiple times.

The time to start monitoring the Geofence.

Constructors

  • Geofence(System.String,Windows.Devices.Geolocation.IGeoshape)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape)

    Initializes a new Geofence object given the id and the shape of the geofence.

    public Geofence(System.String id,Windows.Devices.Geolocation.IGeoshape geoshape)public Geofence(System.String id,Windows.Devices.Geolocation.IGeoshape geoshape)Public Function Geofence(id As System.String,geoshape As Windows.Devices.Geolocation.IGeoshape) As

    Parameters

    • id
      System.String
      System.String
      System.String
      System.String

      The Id of the geofence.

    • geoshape

      The area that defines the geofence to monitor.

    Remarks

    When this constructor is used, the MonitoredStates will default to monitor for both the Entered and Exited states, SingleUse will default to false, the DwellTime will default to 10 seconds, the StartTime will default to 0 meaning start immediately, and the Duration will default to 0, meaning forever.

    The id value must be non-null and less than 64 characters.

    The geoshape parameter must be a non-null Geocircle with a SpatialReferenceId that matches the platform or an exception will be thrown.

  • Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean)

    Initializes a new Geofence object given the id, the shape of the geofence, the states to monitor the geofence for, and the singleUse flag.

    public Geofence(System.String id,Windows.Devices.Geolocation.IGeoshape geoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates monitoredStates,System.Boolean singleUse)public Geofence(System.String id,Windows.Devices.Geolocation.IGeoshape geoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates monitoredStates,System.Boolean singleUse)Public Function Geofence(id As System.String,geoshape As Windows.Devices.Geolocation.IGeoshape,monitoredStates As Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,singleUse As System.Boolean) As

    Parameters

  • Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean,Windows.Foundation.TimeSpan)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean,Windows.Foundation.TimeSpan)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean,Windows.Foundation.TimeSpan)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean,Windows.Foundation.TimeSpan)

    Initializes a new Geofence object given the id, the shape of the geofence, the states to monitor the geofence for, the singleUse flag, and the dwellTime for the geofence.

    public Geofence(System.String id,Windows.Devices.Geolocation.IGeoshape geoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates monitoredStates,System.Boolean singleUse,Windows.Foundation.TimeSpan dwellTime)public Geofence(System.String id,Windows.Devices.Geolocation.IGeoshape geoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates monitoredStates,System.Boolean singleUse,Windows.Foundation.TimeSpan dwellTime)Public Function Geofence(id As System.String,geoshape As Windows.Devices.Geolocation.IGeoshape,monitoredStates As Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,singleUse As System.Boolean,dwellTime As Windows.Foundation.TimeSpan) As

    Parameters

  • Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean,Windows.Foundation.TimeSpan,Windows.Foundation.DateTime,Windows.Foundation.TimeSpan)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean,Windows.Foundation.TimeSpan,Windows.Foundation.DateTime,Windows.Foundation.TimeSpan)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean,Windows.Foundation.TimeSpan,Windows.Foundation.DateTime,Windows.Foundation.TimeSpan)
    Geofence(System.String,Windows.Devices.Geolocation.IGeoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,System.Boolean,Windows.Foundation.TimeSpan,Windows.Foundation.DateTime,Windows.Foundation.TimeSpan)

    Initializes a new Geofence object given the id, the shape of the geofence, the states to monitor the geofence for, the singleUse flag, the dwellTime for the geofence, the time to start monitoring the geofence, and the duration of the geofence.

    public Geofence(System.String id,Windows.Devices.Geolocation.IGeoshape geoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates monitoredStates,System.Boolean singleUse,Windows.Foundation.TimeSpan dwellTime,Windows.Foundation.DateTime startTime,Windows.Foundation.TimeSpan duration)public Geofence(System.String id,Windows.Devices.Geolocation.IGeoshape geoshape,Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates monitoredStates,System.Boolean singleUse,Windows.Foundation.TimeSpan dwellTime,Windows.Foundation.DateTime startTime,Windows.Foundation.TimeSpan duration)Public Function Geofence(id As System.String,geoshape As Windows.Devices.Geolocation.IGeoshape,monitoredStates As Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates,singleUse As System.Boolean,dwellTime As Windows.Foundation.TimeSpan,startTime As Windows.Foundation.DateTime,duration As Windows.Foundation.TimeSpan) As

    Parameters

    Remarks

    You must specify the Entered or Exited states, or both, for a geofence to be monitored. It is not possible to create a geofence that only monitors the Removed state.

    The id value must be non-null and less than 64 characters.

    The geoshape parameter must be a non-null Geocircle with a SpatialReferenceId that matches the platform or an exception will be thrown.

    If the expiration date for the geofence - which is the start time plus the duration time span - occurs sooner than the creation time plus the dwell time value, an exception will be thrown.

Properties

  • Duration
    Duration
    Duration
    Duration

    Gets the time window, beginning after the StartTime, during which the Geofence is monitored.

    public TimeSpan Duration { get; }public TimeSpan Duration { get; }Public ReadOnly Property Duration As TimeSpan

    Property Value

    Remarks

    This property is read-only. Use one of the overloaded Geofence constructors to set the duration value.

    When the duration time window expires, the system automatically removes the geofence from the system and stops monitoring it. If you want your app to be notified when a geofence expires, be sure to include the GeofenceState.Removed state when initializing the geofence.

    The default value for this property is a TimeSpan with a time interval of 0. A time interval of 0 indicates that the geofence will not expire and will be monitored indefinitely or until the app manually removes the geofence.

  • DwellTime
    DwellTime
    DwellTime
    DwellTime

    The minimum time that a position has to be inside or outside of the Geofence in order for the notification to be triggered.

    public TimeSpan DwellTime { get; }public TimeSpan DwellTime { get; }Public ReadOnly Property DwellTime As TimeSpan

    Property Value

    • The minimum time that a position has to be inside or outside of the geofence in order for the notification to be triggered.

    Remarks

    When creating geofences that use a dwell time, the time span must be greater than 0.

    The DwellTime value is used for monitoring both the Entered and Exited states of a single geofence. If you want to provide different dwell time values for entering and exiting, you should create two Geofence objects, using one to track the Entered state and another to track the Exited state. Then you can specify a different dwell time for each object.

  • Geoshape
    Geoshape
    Geoshape
    Geoshape

    The shape of the geofence region.

    public IGeoshape Geoshape { get; }public IGeoshape Geoshape { get; }Public ReadOnly Property Geoshape As IGeoshape

    Property Value

    Remarks

    This property is read-only. You must set the shape of a geofence when you initialize it using one of the constructors.

    The type of this property, IGeoshape, is an interface to enable the possibility of supporting multiple shapes for geofences. The only shape that is currently supported is Geocircle, so this is the class you should use when initializing your geofences.

  • Id
    Id
    Id
    Id

    The id of the Geofence.

    public string Id { get; }public string Id { get; }Public ReadOnly Property Id As string

    Property Value

    • string
      string
      string
      string

      The id of the geofence.

    Remarks

    The Id is limited in length to 63 characters.

    The Id value must be unique among all geofences associated with the same application and user.

  • MonitoredStates
    MonitoredStates
    MonitoredStates
    MonitoredStates

    Indicates the states that the Geofence is being monitored for.

    public MonitoredGeofenceStates MonitoredStates { get; }public MonitoredGeofenceStates MonitoredStates { get; }Public ReadOnly Property MonitoredStates As MonitoredGeofenceStates

    Property Value

    Remarks

    You must specify the Entered or Exited states, or both, for a geofence to be monitored. It is not possible to create a geofence that only monitors the Removed state.

  • SingleUse
    SingleUse
    SingleUse
    SingleUse

    Indicates whether the Geofence should be triggered once or multiple times.

    public bool SingleUse { get; }public bool SingleUse { get; }Public ReadOnly Property SingleUse As bool

    Property Value

    • bool
      bool
      bool
      bool

      True indicates the geofence should be monitored only for one use. False indicates the geofence should be monitored for multiple uses.

    Remarks

    A geofence is considered used when all MonitoredStates have been triggered. If a geofence is only being monitored for the Entered event and SingleUse is set to true, then entering the geofence will mark it as used and it will be removed. If a geofence is being monitored for both Entered and Exited events and SingleUse is set to true, then the geofence will be removed after the user has both entered and exited the geofence.

  • StartTime
    StartTime
    StartTime
    StartTime

    The time to start monitoring the Geofence.

    public DateTime StartTime { get; }public DateTime StartTime { get; }Public ReadOnly Property StartTime As DateTime

    Property Value

    Remarks

    A geofence is made active when the StartTime is in the past. If the device is within the geofence's area when it becomes active and the geofence is being monitored for the Entered state, then the geofence will trigger as soon as the DwellTime requirement has been met. However, if the device is outside of the geofence when it becomes active, the geofence does not instantly switch to the Exited state. The device must enter a geofence, remain inside for the specified DwellTime, and then exit in order to switch to the Exited state.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute

Details

Assembly

Windows.Devices.Geolocation.Geofencing.dll