Geofence Geofence Geofence Geofence Class

Definition

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

public sealed class Geofencepublic sealed class GeofencePublic NotInheritable Class Geofencepublic sealed class Geofence
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Constructors

Geofence(String, IGeoshape) Geofence(String, IGeoshape) Geofence(String, IGeoshape) Geofence(String, IGeoshape)

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

public Geofence(String id, IGeoshape geoshape)public New(String id, IGeoshape geoshape)Public Sub New(id As String, geoshape As IGeoshape)public Geofence(String id, IGeoshape geoshape)
Parameters
id
System.String System.String System.String System.String

The Id of the geofence.

geoshape
IGeoshape IGeoshape IGeoshape IGeoshape

The area that defines the geofence to monitor.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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(String, IGeoshape, MonitoredGeofenceStates, Boolean) Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean) Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean) Geofence(String, IGeoshape, MonitoredGeofenceStates, 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(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse)public New(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse)Public Sub New(id As String, geoshape As IGeoshape, monitoredStates As MonitoredGeofenceStates, singleUse As Boolean)public Geofence(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse)
Parameters
id
System.String System.String System.String System.String

The Id of the geofence.

geoshape
IGeoshape IGeoshape IGeoshape IGeoshape

The area that defines the geofence to monitor.

singleUse
System.Boolean System.Boolean System.Boolean System.Boolean

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean, TimeSpan) Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean, TimeSpan) Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean, TimeSpan) Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean, 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(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse, TimeSpan dwellTime)public New(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse, TimeSpan dwellTime)Public Sub New(id As String, geoshape As IGeoshape, monitoredStates As MonitoredGeofenceStates, singleUse As Boolean, dwellTime As TimeSpan)public Geofence(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse, TimeSpan dwellTime)
Parameters
id
System.String System.String System.String System.String

The Id of the geofence.

geoshape
IGeoshape IGeoshape IGeoshape IGeoshape

The area that defines the geofence to monitor.

singleUse
System.Boolean System.Boolean System.Boolean System.Boolean

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

dwellTime
TimeSpan TimeSpan TimeSpan TimeSpan

The time that a position has to be in or out of the geofence in order for the notification to be triggered. This object must represent a positive value.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean, TimeSpan, DateTime, TimeSpan) Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean, TimeSpan, DateTime, TimeSpan) Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean, TimeSpan, DateTime, TimeSpan) Geofence(String, IGeoshape, MonitoredGeofenceStates, Boolean, TimeSpan, DateTime, 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(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse, TimeSpan dwellTime, DateTime startTime, TimeSpan duration)public New(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse, TimeSpan dwellTime, DateTime startTime, TimeSpan duration)Public Sub New(id As String, geoshape As IGeoshape, monitoredStates As MonitoredGeofenceStates, singleUse As Boolean, dwellTime As TimeSpan, startTime As DateTime, duration As TimeSpan)public Geofence(String id, IGeoshape geoshape, MonitoredGeofenceStates monitoredStates, Boolean singleUse, TimeSpan dwellTime, DateTime startTime, TimeSpan duration)
Parameters
id
System.String System.String System.String System.String

The Id of the geofence.

geoshape
IGeoshape IGeoshape IGeoshape IGeoshape

The area that defines the geofence to monitor.

singleUse
System.Boolean System.Boolean System.Boolean System.Boolean

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

dwellTime
TimeSpan TimeSpan TimeSpan TimeSpan

The time that a position has to be in or out of the geofence in order for the notification to be triggered.This object must represent a positive value.

startTime
DateTime DateTime DateTime DateTime

The time to start monitoring the geofence.

duration
TimeSpan TimeSpan TimeSpan TimeSpan

The duration of time to monitor the geofence for. The duration begins at the startTime. This object must represent a positive value.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 TimeSpanpublic TimeSpan Duration { get; }
Value
TimeSpan TimeSpan TimeSpan TimeSpan

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 TimeSpanpublic TimeSpan DwellTime { get; }
Value
TimeSpan TimeSpan TimeSpan TimeSpan

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 IGeoshapepublic IGeoshape Geoshape { get; }
Value
IGeoshape IGeoshape IGeoshape IGeoshape

The shape of the geofence region.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 stringpublic string Id { get; }
Value
string string string string

The id of the geofence.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 MonitoredGeofenceStatespublic MonitoredGeofenceStates MonitoredStates { get; }
Value
MonitoredGeofenceStates MonitoredGeofenceStates MonitoredGeofenceStates MonitoredGeofenceStates

The states that the geofence is being monitored for.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 boolpublic bool SingleUse { get; }
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.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 DateTimeOffset StartTime { get; }Public ReadOnly Property StartTime As DateTimeOffsetpublic DateTime StartTime { get; }
Value
DateTime DateTime DateTime DateTime

The time to start monitoring the geofence. The default value is 0, which is the beginning of time, epoch.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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.