startMonitoringGeofence()

Start monitoring a geofence region.

Syntax

import { getGeofencingService } from 'lightning/mobileCapabilities';
startMonitoringGeofence(
    geofence: Geofence
): Promise<string>;

Parameters

  • geofence—(Required) A Geofence object to monitor.

Returns

A Promise object that resolves as a string value. The value is a unique ID that’s assigned to the monitored geofence. If there’s an error, a rejected promise returns the error type of GeofenceServiceFailure.

Usage

Use this function to start monitoring of a geofence. 

myGeofenceService.startMonitoringGeofence(geofence)
   .then((id) => {
       const msg = `ID for geofence created: ${id}`;
       console.log(msg);
   })
   .catch((error) => {
       const msg = `Failed to start monitoring:${JSON.stringify(error)}`; 
       console.log(msg);
   });

Your callback function is called to return the ID of the geofence that’s been created. To stop monitoring the geofence in the future, retain the geofence ID.