Share via


GeofenceStateChangeReport Class

Definition

Contains the information about the state changes for a Geofence.

public ref class GeofenceStateChangeReport sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class GeofenceStateChangeReport final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class GeofenceStateChangeReport
Public NotInheritable Class GeofenceStateChangeReport
Inheritance
Object Platform::Object IInspectable GeofenceStateChangeReport
Attributes

Windows requirements

Requirements Description
Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)
App capabilities
location

Examples

Processing geofence state changes

private void ProcessGeofenceReport(GeofenceStateChangeReport report)
{
    switch (report.NewState)
    {
        case GeofenceState.Entered:
            // App-specific: start location-based services, log entry
            HandleGeofenceEntry(report.Geofence.Id, report.Geoposition);
            break;

        case GeofenceState.Exited:
            // App-specific: stop services, calculate dwell time
            HandleGeofenceExit(report.Geofence.Id);
            break;

        case GeofenceState.Removed:
            // Check why the geofence was removed and handle accordingly
            if (report.RemovalReason == GeofenceRemovalReason.Expired)
            {
                // App-specific: recreate geofence if still needed
                HandleExpiredGeofence(report.Geofence.Id);
            }
            else if (report.RemovalReason == GeofenceRemovalReason.Used)
            {
                // App-specific: single-use geofence completed successfully
                HandleCompletedGeofence(report.Geofence.Id);
            }
            break;
    }
}

Remarks

Use the GeofenceMonitor.ReadReports method to get a collection of GeofenceStateChangeReport objects which contain information about changes in state to a geofence.

Key properties

  • Geofence: The geofence that changed state
  • NewState: Current state (Entered, Exited, or Removed)
  • Geoposition: Location information when the state change occurred
  • RemovalReason: Why the geofence was removed (if applicable)

Report lifecycle

State change reports accumulate in the system until consumed by calling ReadReports. Each call to ReadReports clears the report queue and returns all pending reports since the last read. Reports may contain multiple state changes for the same geofence if events occurred rapidly.

Note

Reports are available both when the app is running in the foreground (via GeofenceStateChanged events) and when returning from background suspension. Background tasks should always call ReadReports to process accumulated events.

Properties

Name Description
Geofence

The Geofence object whose state has changed.

Geoposition

The position of the Geofence object whose state has changed.

NewState

The new state of the Geofence object whose state has changed.

RemovalReason

Indicates the reason a Geofence was removed.

Applies to

See also