Monitor POIs with Geofence

Monitor POIs with Geofence using Cordova 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
        const request = {
    "lat": 51.50998000,
    "lng": -0.13370000,
    "regionId": "7F91369E-467C-4CBD-8D41-6509815C4780",
    "radius": 10
};
cordova.plugins.WoosmapGeofencing.addRegion(request, success, error);

    

Remove regions

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

JavaScript
        const request = {
    "lat": 51.50998000,
    "lng": -0.13370000,
    "regionId": "7F91369E-467C-4CBD-8D41-6509815C4780",
    "radius": 10
};
cordova.plugins.WoosmapGeofencing.removeRegion(request, success, 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
        const success = function (regions) {
    showSuccessToast("Total Regions: " + regions.length);
};
cordova.plugins.WoosmapDb.getRegions(success, 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
        const regionCallback = function (region) {
    console.log("Region:" + region);
};

const error = function (err) {
    console.log(err);
};

const regionWatchId = cordova.plugins.WoosmapGeofencing.watchRegions(regionCallback, error);

    

To remove watch:

JavaScript
        cordova.plugins.WoosmapGeofencing.clearRegionsWatch(regionWatchId, success, error);

    

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