How to create geofences in the map widget with muliple devices

Hi

I am having a problem setting up geofences with multiple devices as laid out below.
I agree you can add many devices within a geofence on the map widget and all will look fine as below.

map

The problem comes in when you try to store the geofence meta data in the bucket of each device as I will try to show bellow.

Here you add the devices and the variable where the location data is stored in the bucket for each device….no problem.add device

Here you are meant to be able to add the device and the variable for the geofence in the bucket for each device but you encounter a problem.add geofence1

Although you can see all the devices you can only save one device with its variable in this case “inside_geo”
add geofence2

What this means is that although you may have many devices only one device has the geofence.
When you run analytics with the device with the geofence stored in its bucket you can create notifications to the user.
E.g. “Tracker_001” with geofence variable “inside_geo”

When you run analytics with any other device you cannot create notifications to the user.
E.g. “ Tracker_002” unable to save variable.

Our work around has been to add the geofence meta data for each device manually using the device emulator.
This is impractical with 300 devices and will not allow for users to edit their own geofences.

Any advice will be appreciated.

Flaxies

The Geofence variable is where all the geofence data (coordinates) are stored. You could create a new blueprint device or a new blueprint tag with this variable so you can choose on the widget edit page.

If you want to show a notification if the device Tracker_001 is inside a geofence you could use analysis like this post link for the post, is not necessary a variable for telling if the device is inside or not the geofence if this is your goal. In the linked topic I show how to implement an Analysis for a single device, but is possible to improve the Action trigger for multiple devices and replace this part of the code

  // Here we get the device information using our account data and the device id.
  const device = await getDevice(account, device_id);

  // This checks if we received a location
  const location = scope.find((data) => data.variable === "YourLocationVariable");
  if (!location || !location.location) return context.log("No location found in the scope.");
  // Now we check if we have any geofences to go through.
  const geofences = await device.getData({ variable: "YourGeofenceVariableName", qty: 10 });
  const zones = geofences.map((geofence) => geofence.metadata);

For something like this

  // Here we get the device information using our account data and the device id.
  const device = await getDevice(account, device_id);

  // This checks if we received a location
  const location = scope.find((data) => data.variable === "YourLocationVariable");
  if (!location || !location.location) return context.log("No location found in the scope.");
  // Now we check if we have any geofences to go through.
  const deviceGeofence = await getDevice(account, "Device with geofences id");
  const geofences = await deviceGeofence.getData({ variable: "YourGeofenceVariableName", qty: 10 });
  const zones = geofences.map((geofence) => geofence.metadata);

Where the device that has the geofences coordinates is static inside the code and the device that you want to test if the location is inside the geofences can be dynamic.

Let me know if this works for you and where I can help you.
Thanks, Filipe.