Geofence​Monitor Geofence​Monitor Geofence​Monitor Class

Definition

Contains the information about the monitored Geofence objects.

public sealed class GeofenceMonitor : IGeofenceMonitorpublic sealed class GeofenceMonitor : IGeofenceMonitorPublic NotInheritable Class GeofenceMonitor Implements IGeofenceMonitor
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

Use the static Current property to get the GeofenceMonitor object which contains all of an app’s geofence information.

You will receive an IDS_GEOFENCEMONITOR_OUT_OF_SYNC exception if the Location Framework Service event state is out of synchronization with the GeofenceMonitor. You can attempt to recover by removing all event handlers on the GeofenceMonitor or restarting the application. Once all event handlers have been removed, you may add back any event handlers and retry the operation.

Properties

Current Current Current

Gets the GeofenceMonitor object which contains all of an app's Geofence information.

public static GeofenceMonitor Current { get; }public static GeofenceMonitor Current { get; }Public Static ReadOnly Property Current As GeofenceMonitor
Value
GeofenceMonitor GeofenceMonitor GeofenceMonitor

Gets the GeofenceMonitor object which contains all of an app's geofence information.

Attributes

Geofences Geofences Geofences

Returns a vector of the app's Geofence objects currently registered with the system-wide GeofenceMonitor.

public IVector<Geofence> Geofences { get; }public IVector<Geofence> Geofences { get; }Public ReadOnly Property Geofences As IVector<Geofence>
Value

A collection of the Geofence objects to monitor.

Attributes

Remarks

Register a Geofence to be monitored by the system by adding it to this collection.

Geofences are persisted to disk, so they only need to be added to the system once. Attempting to add a Geofence with an Id that is already registered will throw an exception.

Attempting to remove a Geofence from the Geofences property will fail with an exception if the specified Geofence is registered with the system but does not belong to the calling application's collection.

This vector reflects only updates made by the app. To view changes made by the system, as in after a single-use Geofence is triggered and removed, the app can call this property again or safely remove the removed Geofence from a previously returned vector.

LastKnownGeoposition LastKnownGeoposition LastKnownGeoposition

Last reading of the device's location.

public Geoposition LastKnownGeoposition { get; }public Geoposition LastKnownGeoposition { get; }Public ReadOnly Property LastKnownGeoposition As Geoposition
Value
Geoposition Geoposition Geoposition

Last reading of the device's location.

Attributes

Remarks

Before using the value from this property, the application must first check that the value is not NULL.

Status Status Status

Indicates the current state of the GeofenceMonitor.

public GeofenceMonitorStatus Status { get; }public GeofenceMonitorStatus Status { get; }Public ReadOnly Property Status As GeofenceMonitorStatus
Attributes

Methods

ReadReports() ReadReports() ReadReports()

Gets a collection of status changes to the Geofence objects in the Geofences collection of the GeofenceMonitor.

public IVectorView<GeofenceStateChangeReport> ReadReports()public IVectorView<GeofenceStateChangeReport> ReadReports()Public Function ReadReports() As IVectorView( Of GeofenceStateChangeReport )
Returns

collection of status changes to the Geofence object(s) in GeofenceMonitor.

Attributes

Remarks

Each report in the collection contains the most recent state for the geofences that changed state since the last time ReadReports was called. Older state changes may be present in the collection if ReadReports hasn't been called over a period of time when many geofence state changes have occurred, but the system may purge these older state changes.

The collection returned from this method may be empty and contain no GeofenceStateChangeReport objects. This can happen if no status changes have occurred since the last time the method was called, either by the app or the background task.

Events

GeofenceStateChanged GeofenceStateChanged GeofenceStateChanged

Raised when the state of one or more Geofence objects in the Geofences collection of the GeofenceMonitor has changed

public event TypedEventHandler GeofenceStateChangedpublic event TypedEventHandler GeofenceStateChangedPublic Event GeofenceStateChanged
Attributes

Remarks

This event is raised when your app is running and the state of a geofence registered by your app changes. This event is also raised when your app activates if there are unread reports in the collection obtained by calling ReadReports. This allows an app that is coming back from being suspended to be notified that there are unread reports in the queue and update the UI accordingly. This also allows your app to read reports that occurred in the background in cases where your background task was not launched to due to conditions set with SystemCondition, such as waiting for an internet connection or waiting for the user to be present.

StatusChanged StatusChanged StatusChanged

Raised when the status of the GeofenceMonitor has changed.

public event TypedEventHandler StatusChangedpublic event TypedEventHandler StatusChangedPublic Event StatusChanged
Attributes

Remarks

When using a geofence, use the GeofenceMonitor 's StatusChanged event to monitor changes in location permissions instead of the StatusChanged event from the Geolocator class. A GeofenceMonitorStatus of Disabled is equivalent to a **Disabled **PositionStatus - both indicate that the app does not have permission to access the location.

See Also