Cordova Plugin

Setup the Woosmap Geofencing SDK using the Cordova Plugin

  1. Install the Cordova Plugin
  2. Running the plugin on the Android platform

The Woosmap Geofencing SDK allows you to monitor Geofences, track your user’s location and connect with the Woosmap Search and Distance APIs.

Learn how to integrate the Cordova Plugin below. You can also explore the source code on GitHub to get deeper into it.

Install the Cordova Plugin

Prerequisites

Before you begin, make sure you have installed and setup Cordova on your machine. See this Get Started on official Cordova Documentation.

Create your cordova app

cordova create <folder_name> <package_name> <project_name>
cd <folder_name>

Adding the platform

For iOS

cordova platform add [email protected]
cordova plugin add cordova-plugin-add-swift-support --save

For Android

cordova plugin add cordova-plugin-androidx
cordova platform add android

Woosmap Geofencing Cordova plugin

Add the Woosmap Geofencing Cordova plugin to your project using this command line:

cordova plugin add @woosmap/cordova-plugin-geofencing --link

Running the plugin on the Android platform

Once you have done this build and run the project using following command:

cordova build
cordova run <android>/<ios>

Supported Platforms

Modules

Objects(Read Only)

Initializing the plugin

Plugin can be initialized by simply calling initialize method.

var woosmapSettings = {
    privateKeyWoosmapAPI: "<<WOOSMAP_KEY>>",
    trackingProfile: "liveTracking"
};
cordova.plugins.Woosmap.initialize(woosmapSettings, onSuccess, onError);
var onSuccess = function () {
    console.log("success");
};
var onError = function (error) {
    alert('message: ' + error.message);
};

Both configuration options privateKeyWoosmapAPI and trackingProfile are optional. You can also initialize the plugin by passing null configuration.

cordova.plugins.Woosmap.initialize(null, onSuccess, onError);

You can also set the Woosmap API key later by calling setWoosmapApiKey method.

cordova.plugins.Woosmap.setWoosmapApiKey(<privateKeyWoosmapAPI>, onSuccess, onError);

Listening to location event

To listen to location, call watchLocation method. Method will invoke callback and pass a location object as a parameter. Method will return a watchId . This id can be used to remove a callback.

const locationCallback = function (location) {
    const wgsLocation = window.WoosmapGeofencing.Location.jsonToObj(location);
    console.log("Location:" + wgsLocation.Latitude + "," + wgsLocation.Longitude);
};

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

const locationWatchId = cordova.plugins.WoosmapGeofencing.watchLocation(locationCallback, error);

To stop getting location updates:

cordova.plugins.WoosmapGeofencing.clearLocationWatch(locationWatchId, success, error);

Get locations from the local database

Call getLocations method to get an array of Locations from the local db.

const success = function (locations) {
    console.log("Locations >>", locations);
    showSuccessToast("Total Locations: " + locations.length);
};
cordova.plugins.WoosmapDb.getLocations(success, error);
Was this article helpful?
Have more questions? Submit a request