The plugin allows you to define perimeters, also referred to as geofences, which surround the areas of interest. Your app gets a notification when the device crosses a geofence, which allows you to provide a useful experience when users are in the vicinity.
To use GeoFence plugin, you must first load the plugin at the top of your script using the LoadPlugin method of the app object like this:
Once you have the plugin loaded, you can create an instance of the GeoFence plugin by calling the CreateGeoFence method of the app object like this:
For polygon boundary:
path |
Array Required. An array of latLng literal objects for the series of points on a polygon |
name |
String Required. The name of the polygon geofence |
// This path creates a polygon with four points var path = [ {lat: 65.692266, lng: -26.712499}, {lat: 65.836578, lng: 65.748431}, {lat: 27.600915, lng: 65.045306}, {lat: 25.244269, lng: -21.096074} ]
path |
Array Required. The new array of latLng literal objects for the new path of an existing polygon |
name |
String Required. The name of the polygon geofence to be set |
lat |
Number Required. The latitude of the center |
lng |
Number Required. The longitude of the center |
radius |
Number Required. The radius in meters |
name |
String Required. The name of the circle geofence |
newLat |
Number Required. The new latitude of the center |
newLng |
Number Required. The new longitude of the center |
newRadius |
Number Required. The new radius in meters |
name |
String Required. The name of the circle geofence to be set |
newLat |
Number Required. The new latitude of the center |
newLng |
Number Required. The new longitude of the center |
name |
String Required. The name of the circle geofence to be set |
newRadius |
Number Required. The new radius in meters. |
name |
String Required. The name of the circle geofence to be set |
callback |
Function Required. The function to be called when there's a change of value. Returns: true for entering (inside) or false for leaving (outside) |
app.LoadPlugin("GeoFence") function OnStart() { var path = [ {lat: 65.692266, lng: -26.712499}, {lat: 65.836578, lng: 65.748431}, {lat: 27.600915, lng: 65.045306}, {lat: 25.244269, lng: -21.096074} ] fence = app.CreateGeoFence() fence.AddPolygon(path, "FirstFence") fence.SetOnChange(OnFenceChange) fence.Start() } function OnFenceChange(val, name) { if(val) app.ShowPopup("You are entering the boundary of " + name) else app.ShowPopup("You are leaving the boundary of" + name) }
app.LoadPlugin("GeoFence"); function OnStart() { var lat = 46.979536, lng = 2.215101, radius = 1000000 //1000 kilometers from the center of FRANCE fence = app.CreateGeoFence() fence.AddCircle(lat, lng, radius, "CircleFence") fence.SetOnChange(OnFenceChange) fence.Start() } function OnFenceChange(val, name) { if(val) app.ShowPopup("You are entering the boundary" + name) else app.ShowPopup("You are leaving the boundary" + name) }
app.LoadPlugin("GeoFence") function OnStart() { var lat = 46.979536, lng = 2.215101, radius = 1000000 //1000 kilometers from the center of FRANCE var path = [ {lat: 65.692266, lng: -26.712499}, {lat: 65.836578, lng: 65.748431}, {lat: 27.600915, lng: 65.045306}, {lat: 25.244269, lng: -21.096074} ] fence = app.CreateGeoFence() fence.AddPolygon(path, "PolygonFence") fence.AddCircle(lat, lng, radius, "CircleFence") fence.SetOnChange(OnFenceChange) fence.Start() } function OnFenceChange(val, name) { if(val && name == "PolygonFence") { app.ShowPopup("You are entering the Polygon fence") } else if(val && name == "CircleFence") { app.ShowPopup("You are entering the Circle fence") } }