Arbitrary key-values appended to the geofence event and posted to your configured Config.url.
Unique geofence identifier.
Latitude of geofence center
Minimum time in milliseconds the device must "loiter" within this geofence before notifyOnDwell event fires.
Longitude of geofence center.
Set true
to fire event when device "loiters" within this geofence for loiteringDelay milliseconds.
Set true
to fire event when device enters this geofence.
ℹ️ See also:
Set true
to fire event when device exits this geofence.
Radius of the circular geofence.
⚠️ The minimum reliable radius
is 200
meters. Anything less will likely not cause a geofence to trigger. This is documented by Apple here:
"The specific threshold distances are determined by the hardware and the location technologies that are currently available. For example, if WiFi is disabled, region monitoring is significantly less accurate. However, for testing purposes, you can assume that the minimum distance is approximately 200 meters".
Optional: a list of vertices ([ [lat, lng],...]
) defining a Polygon geofence. By default, geofences are circular.
ℹ️ Polygon Geofencing is sold as a separate add-on (fully functional in DEBUG builds).
When defining a polygon geofence, you do not provide latitude, longitude or radius — those will be automatically calculated based upon the geometry of the polygon.
The following image shows polygon geofences on a map:
The blue polygons represent the actual polygon geofences and the containing green circles are traditional circular geofences provided by the native iOS/Android Geofencing APIs. The background-geolocation SDK automatically calculates the containing, native cirular geofence by solving the minimum enclosing circle for the given vertices. This is why you do not provide latitude, longitude and radius.
Generated using TypeDoc
The Background Geolocation SDK implements the native iOS and Android Geofencing APIs.
ℹ️ Note:
200
meters.Always
—When in Use
will not work.Adding Geofences
Adding a single geofence with addGeofence.
Adding multiple geofences with addGeofences.
ℹ️ Note: Adding a geofence having an identifier which already exists within the SDK geofence database will cause the previous record to be destroyed and the new one inserted.
Listening for Geofence Events
Listen to geofence events with BackgroundGeolocation.onGeofence.
Polygon Geofencing
The Background Geolocation SDK supports Polygon Geofences (Geofences of any shape). See API docs vertices.
Infinite Geofencing
The Background Geolocation SDK contains unique and powerful Geofencing features that allow you to monitor any number of circular geofences you wish (thousands even), in spite of limits imposed by the native platform APIs (20 for iOS; 100 for Android).
The SDK achieves this by storing your geofences in its database, using a geospatial query to determine those geofences in proximity (geofenceProximityRadius), activating only those geofences closest to the device's current location (according the limit imposed by the corresponding platform).
1000
meters.Listening for changes in the actively-monitored set-of-geofences.
As the SDK periodically queries for geofences within the geofenceProximityRadius, you can listen for changes in the actively-monitored geofences using the event onGeofencesChange. This event will let you know those geofences which have begun to be actively monitored (GeofencesChangeEvent.on) in addition to those which just ceased to be actively monitored (GeofencesChangeEvent.off).
⚠️ Note:
Removing Geofences
Once a geofence has been inserted into the SDK's database using addGeofence or addGeofences, they will be monitored forever (as long as the plugin remains
State.enabled == true
). If you've configured stopOnTerminatefalse
and startOnBoottrue
, geofences will continue to be monitored even if the application is terminated or device rebooted. To cease monitoring a geofence or geofences, you must remove them from the SDK's database (or call BackgroundGeolocation.stop).Querying Geofences
Use the method getGeofences to retrieve the entire Array of Geofence stored in the SDK's database.
Monitoring only geofences
The BackgroundGeolocation SDK allows you to optionally monitor only geofences without constant location-tracking. To engage geofences-only mode, use the method startGeofences instead of start.
Use option Config.geofenceModeHighAccuracy:true to improve the responsiveness of geofence events.
Toggling between tracking-modes start and startGeofences
The SDK can easily be toggled between State.trackingMode simply by executing the corresponding start or startGeofences methods.