vertices property

List<List<double>>? vertices
getter/setter pair

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.

  • When the device enters the containing circular geofence, the SDK uses that as a signal that the device is approaching a polygon. At this moment, the SDK begins aggressively monitoring the location to perform "hit-testing" upon the polygon using a fast algorithm implemented with C++ code.
  • When the device exits the containing circular geofence, that's the SDK's signal for it to cease monitoring that polygon.

Example

BackgroundGeolocation.addGeofence(Geofence(
  identifier: 'Home',
  notifyOnEntry: true,
  notifyOnExit: true,
  vertices: [
    [45.518947279987714, -73.6049889209514],  // <-- [lat, lng]
    [45.5182711292279, -73.60338649600598],
    [45.517082240237634, -73.60432670908212],
    [45.51774871402813, -73.60604928622278]
  ]
));

Entering / exiting a cross-shaped polygon geofence.:

Entering / exiting a park:

Entering / exiting a diamond-shaped polygon:

Designing a polygon geofence around a park using the demo app:

Implementation

List<List<double>>? vertices;