Examples

Install the module

Run the following command to install the module (make sure to install the core module beforehand):

npm i @sentiance-react-native/smart-geofences

Import the module

import SentianceSmartGeofences from "@sentiance-react-native/smart-geofences";

You can find a reference to all the types mentioned on this page here.

Refresh the list of monitored geofences

import {refreshGeofences} from "@sentiance-react-native/smart-geofences";

try {
     await refreshGeofences();
     console.log("Geofences refreshed successfully.");
} catch (error) {
     const refreshError = error.userInfo;
     const {reason, details} = refreshError;
     
     console.error("Refresh error reason:", reason);
     console.error("Refresh error details:", details);
}

Listen to smart geofence entry/exit events

import {addSmartGeofenceEventListener} from "@sentiance-react-native/smart-geofences";

const subscription = addSmartGeofenceEventListener(smartGeofenceEvent => {
  // Smart geofence entry/exit detected
  
  const eventTime = smartGeofenceEvent.timestamp;
  const triggeringLocation = smartGeofenceEvent.triggeringLocation;
  const eventType = smartGeofenceEvent.eventType;
  
  const geofences = smartGeofenceEvent.geofences;
  geofences.forEach(geofence => {
    const sentianceId = geofence.sentianceId;
    const latitude = geofence.latitude;
    const longitude = geofence.longitude;
    const radius = geofence.radius;
    const externalId = geofence.externalId;
  });
});

// Don't forget to unsubscribe, typically in componentWillUnmount
subscription.remove();

Get the smart geofences detection mode

import {getDetectionMode} from "@sentiance-react-native/smart-geofences";

const detectionMode = await getDetectionMode();
console.log('Detection mode is currently:', detectionMode);