GeofenceMonitor GeofenceMonitor GeofenceMonitor GeofenceMonitor Class

Definition

Contains the information about the monitored Geofence objects.

public : sealed class GeofenceMonitor : IGeofenceMonitor
public sealed class GeofenceMonitor : IGeofenceMonitor
Public NotInheritable Class GeofenceMonitor Implements IGeofenceMonitor
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
location

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 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
var geofenceMonitor = Windows.Devices.Geolocation.Geofencing.GeofenceMonitor.current;
Value
GeofenceMonitor GeofenceMonitor GeofenceMonitor GeofenceMonitor

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

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

Geofences 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 IList<Geofence> Geofences { get; }
Public ReadOnly Property Geofences As IList<Geofence>
var iList = geofenceMonitor.geofences;
Value
IVector<Geofence> IList<Geofence> IList<Geofence> IList<Geofence>

A collection of the Geofence objects to monitor.

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

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 LastKnownGeoposition

Last reading of the device's location.

public : Geoposition LastKnownGeoposition { get; }
public Geoposition LastKnownGeoposition { get; }
Public ReadOnly Property LastKnownGeoposition As Geoposition
var geoposition = geofenceMonitor.lastKnownGeoposition;
Value
Geoposition Geoposition Geoposition Geoposition

Last reading of the device's location.

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

Remarks

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

Status Status Status Status

Indicates the current state of the GeofenceMonitor.

public : GeofenceMonitorStatus Status { get; }
public GeofenceMonitorStatus Status { get; }
Public ReadOnly Property Status As GeofenceMonitorStatus
var geofenceMonitorStatus = geofenceMonitor.status;
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
location

Methods

ReadReports() 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 IReadOnlyList<GeofenceStateChangeReport> ReadReports()
Public Function ReadReports() As IReadOnlyList<GeofenceStateChangeReport>( Of GeofenceStateChangeReport )
var iVectorView = geofenceMonitor.readReports();
Returns
IVectorView<GeofenceStateChangeReport> IReadOnlyList<GeofenceStateChangeReport> IReadOnlyList<GeofenceStateChangeReport> IReadOnlyList<GeofenceStateChangeReport>

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

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

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 GeofenceStateChanged

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

public : event TypedEventHandler GeofenceStateChanged<GeofenceMonitor,  object>
public event TypedEventHandler GeofenceStateChanged<GeofenceMonitor,  object>
Public Event TypedEventHandler GeofenceStateChanged( Of ( Of GeofenceMonitor ), ( Of  object ))
function onGeofenceStateChanged(eventArgs){/* Your code */}


geofenceMonitor.addEventListener("geofenceStateChanged", onGeofenceStateChanged);
geofenceMonitor.removeEventListener("geofenceStateChanged", onGeofenceStateChanged);
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
location

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 StatusChanged

Raised when the status of the GeofenceMonitor has changed.

public : event TypedEventHandler StatusChanged<GeofenceMonitor,  object>
public event TypedEventHandler StatusChanged<GeofenceMonitor,  object>
Public Event TypedEventHandler StatusChanged( Of ( Of GeofenceMonitor ), ( Of  object ))
function onStatusChanged(eventArgs){/* Your code */}


geofenceMonitor.addEventListener("statusChanged", onStatusChanged);
geofenceMonitor.removeEventListener("statusChanged", onStatusChanged);
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
location

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