-
Notifications
You must be signed in to change notification settings - Fork 426
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)
.
A unique String
to identify your Geofence, eg: "Home", "Office".
The radius of the circular geofence. A radius of >100 meters works best.
Transitioning into the geofence will generate an event.
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, taskId) {
try {
var identifier = geofence.identifier;
var action = geofence.action;
var location = geofence.location;
console.log("- A Geofence transition occurred");
console.log(" identifier: ", identifier);
console.log(" action: ", action);
console.log(" location: ", JSON.stringify(location));
} catch(e) {
console.error("An error occurred in my code!", e);
}
// Be sure to call #finish!!
bgGeo.finish(taskId);
});
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];
var marker = new google.maps.Circle({
radius: parseInt(geofence.radius, 10),
center: new google.maps.LatLng(geofence.latitude, geofence.longitude),
map: myMapInstance
});
}
});