-
Notifications
You must be signed in to change notification settings - Fork 24
Geofence Features
The plugin includes native geofencing features. You may add, remove and query the list of monitored geofences from the native plugin. The native plugin will persist monitored geofences and re-initiate them when the app boots or the device is restarted.
You can demo these features right now using the SampleApp.
A monitored geofence will remain active until you explicity remove it via bgGeo.removeGeofence(identifier)
.
#####@param {String} identifier
A unique String
to identify your Geofence, eg: "Home", "Office".
#####@param {Integer} radius
The radius of the circular geofence. A radius of >100 meters works best.
#####@param {Boolean} notifyOnEntry
Transitioning into the geofence will generate an event.
#####@param {Boolean} notifyOnExit
Transitioning out of the geofence will generate an event.
Listen to geofence transition events using the method #onGeofence
. You may set up any number of #onGeofence
event-listeners throughout your code -- they will all be executed.
bgGeo.addGeofence({
identifier: "Home",
radius: 200,
latitude: 47.2342323,
longitude: -57.342342,
notifyOnEntry: true
});
bgGeo.onGeofence(function(geofence) {
console.log("- A Geofence transition occurred");
console.log(" identifier: ", geofence.identifier);
console.log(" action: ", geofence.action);
});
The native plugin will continue to monitor geofences and fire transition-events until you explicity tell the plugin to remove a geofence via #removeGeofence(identifier)
.
bgGeo.removeGeofence("Home");
The native plugin persists monitored geofences between application boots and device restarts. When your app boots, you can fetch the currently monitored geofences from the native plugin and, for example, re-draw markers on your map.
bgGeo.getGeofences(function(geofences) {
for (var n=0,len=geofences.length;n<len;n++) {
var geofence = geofences[n];
// Create marker on your map-of-choice
}
});