starti.app
How to

Use Geofencing

Set up geofence regions and respond to enter and exit events

Use Geofencing

Create and manage geofences to trigger actions when users enter or exit geographic areas.

Prerequisites

  • The starti.app SDK is installed and initialized
  • Location access is granted

Request location access

await startiapp.Location.requestAccess();

Create a geofence

Define a circular region with a center point and radius:

await startiapp.Location.createGeofence({
  identifier: "office",
  center: {
    latitude: 55.6761,
    longitude: 12.5683,
  },
  radius: {
    totalKilometers: 0.5,
  },
  notifyOnEntry: true,
  notifyOnExit: true,
});

Listen for geofence events

startiapp.Location.addEventListener("onRegionEntered", (event) => {
  console.log("Entered region:", event.detail.identifier);
});

startiapp.Location.addEventListener("onRegionExited", (event) => {
  console.log("Exited region:", event.detail.identifier);
});

List active geofences

const geofences = await startiapp.Location.getGeofences();
console.log("Active geofences:", geofences);

Remove a geofence

await startiapp.Location.removeGeofence({
  identifier: "office",
  center: { latitude: 55.6761, longitude: 12.5683 },
  radius: { totalKilometers: 0.5 },
});

GeofenceRegion fields

FieldTypeDescription
identifierstringUnique name for this geofence
center{ latitude, longitude }Center point of the region
radius{ totalKilometers }Radius in kilometers
notifyOnEntrybooleanFire event when user enters (optional)
notifyOnExitbooleanFire event when user exits (optional)

See also

On this page