Cordova Plugin
Setup the Woosmap Geofencing SDK using the Cordova Plugin
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
- iOS (Plugin supports iOS 12 and higher)
- Android (Plugin supports Android 9 and higher)
App closed limitations Because of the Cordova framework, callbacks are not triggered when the application is closed. Locations and geofence events are well stored in the device, and you can retrieve them through getter methods included in this plugin.
Modules
- Woosmap: Woosmap contains methods to monitor location, POIs, regions and visits.
- WoosmapDb: contains methods to fetch POIs, regions and visits from the local device DB.
Objects(Read Only)
- Location: Represents the location object
- POI: Represents Point of Interest
- Region: Represents a geographical region/Geofence
- Visit: Represents a visit to a location/POI
- ZOI: Represents Zone of Interest
- Airship: Contains custom data related to Airship implementation
- MarketingCloud: Contains custom data related to third party marketing cloud implementation
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);