Develop Secure Code
GeofencingService Data Types
getGeofencingService()
isAvailable()
startMonitoringGeofence()
stopMonitoringGeofence()
stopMonitoringAllGeofences()
getMonitoredGeofences
Start monitoring a geofence region.
1import { getGeofencingService } from 'lightning/mobileCapabilities';
2startMonitoringGeofence(
3 geofence: Geofence
4): Promise<string>;geofence—(Required) A Geofence object to monitor.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.
Use this function to start monitoring of a geofence.
1myGeofenceService.startMonitoringGeofence(geofence)
2 .then((id) => {
3 const msg = `ID for geofence created: ${id}`;
4 console.log(msg);
5 })
6 .catch((error) => {
7 const msg = `Failed to start monitoring:${JSON.stringify(error)}`;
8 console.log(msg);
9 });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.