Monitor POIs with Geofence

Monitor POIs with Geofence using React Native Plugin

  1. Create and monitor Geofences
  2. Adding and removing regions
  3. Create regions from Woosmap Search API assets

Create and monitor Geofences

Use region monitoring to determine when the user enters or leaves a geographic region.

Region monitoring (also known as Geofencing) combines awareness of the user’s current location with awareness of the user’s proximity to locations that may be of interest. This region is a way for your app to be alerted when the user enters or exits a geographical region. To mark a location of interest, you specify its latitude and longitude. To adjust the proximity for the location, you add a radius. The latitude, longitude, and radius define a Geofence, creating a circular area, or fence, around the location of interest. Find more details about Geofences in the Geofence documentation

Adding and removing regions

Call addRegion method to add a region that you want to monitor. Method will accept an object with the following attributes:

JavaScript
        var regionData = {
    lat: 51.50998,
    lng: -0.1337,
    regionId: '7F91369E-467C-4CBD-8D41-6509815C4780',
    radius: 100,
    type: 'circle', //or "isochrone"
};
WoosmapGeofencing.addRegion(regionData)
    .then((value: string) => {
        console.log(value);
    })
    .catch((error: any) => {
        console.error(error);
    });

    

Remove regions

Call removeRegion method to add a region. Method will accept the following parameter, and passing a null value will remove all the regions.

JavaScript
        const request = "7F91369E-467C-4CBD-8D41-6509815C4780";
WoosmapGeofencing.removeRegions(request)
    .then((value: string) => {
        console.log(value);
    })
    .catch((error: any) => {
        console.error(error);
    });

    

Whenever the user crosses the boundary of one of your app’s registered regions, the system notifies your app.

On the object Region, there are an boolean didEnter that indicate if you enter or exit of the region. You have another boolean fromPositionDetection to know if the detection was launch by the position detection or by the system detection.

Regions have an associated identifier, which this method uses to look up information related to the region and perform the associated action.

Get regions from the local database

Call getRegions method to get an array of Regions from the local db.

JavaScript
        WoosmapGeofencing.getRegions(regionId) //regionId is optional
    .then((value: Region[]) => {
        Toast.show(String(value.length));
    })
    .catch((error: any) => {
        console.error(error);
    });

    

Watch Region to track region’s events

Call watchRegions method to track Regions. Method will invoke a callback with Region object. Method will return a watch id which can be used later to remove the callback.

JavaScript
        WoosmapGeofencing.watchRegions(callback)
    .then((watchRef: string) => {
        //Keep watchRef, it requires when you wish to remove region watch.
        console.log('Watch added');
    })
    .catch((error: any) => {
        alert('message: ' + error.message);
    });

    

To remove watch:

JavaScript
        WoosmapGeofencing.clearRegionsWatch(watchID)
    .then((watchRef: string) => {
        console.log(watchRef);
    })
    .catch((error: any) => {
        alert('message: ' + error.message);
    });

    

Create regions from Woosmap Search API assets

Region monitoring is a natural complement to Search requests performed on collected locations. Indeed, Search requests help monitoring the approach to some assets you want to monitor. On every collected location you are aware of the surrounding assets (distance to them and even time if using Distance API request). You can then decide to monitor some of those surrounding assets (e.g. the closest ones). Region monitoring is designed to do so.

To create region around the nearest result of the Search API request, choose a tracking profile with the tracking properties searchAPICreationRegionEnable enable.

Pre-requisites
You must define a Woosmap private API key to request the Woosmap Search API. How set an Woosmap private key is explain in the Initializing the plugin section.

Was this article helpful?
Have more questions? Submit a request