Geofencing triggers multiple tasks

Please provide the following:

  1. SDK Version: 39
  2. Platforms(Android/iOS/web/all): Android & IOS

I’ve implemented geofencing in my app following the documentation on https://docs.expo.io/versions/latest/sdk/location/#geofencing-methods.

I am facing several weird outcomes:
1.I defined 2 background tasks with TaskManager.defineTask (https://docs.expo.io/versions/latest/sdk/task-manager/) - TaskA and TaskB. Then I registered geofences with locationStartGeofencingAsync for Loc1 with TaskA and another for Loc2 with TaskB. (i.e. locationStartGeofencingAsync(TaskA,Loc1) and locationStartGeofencingAsync(TaskB,Loc2) ).

Expected Outcome:
geofence trigger for Loc1 => TaskA,
geofence trigger for Loc2 => TaskB

Actual outcome:
geofence trigger for Loc1 => Task A & Task B
geofence trigger for Loc2 => Task A & Task B

I can work around it, BUT my question is: isn’t it possible to define different geofence task for different geofence?

  1. another unexpected outcome is that on IOS I receive exit notification even when notifyOnExit is set to false. Same for entry on IOS when notifyOnEnter is set to false. (works perfectly on Anrdoid).
    I can work around it as well, BUT it is missing the point of notifyOnEnter and notifyOnExit.
    Is this the expected behaviour on IOS?

@charliecruzan I believe you are the Expo expert for this topic. Appreciate your thoughts on the above. Thanks!

hi @haggaisch, how are you registering your tasks? An example Snack would be very helpful here :smile:

for the sake of simplicity this is how I register the tasks:
export const GEOFENCING_TASK_A = “geofencing-task-A”;
export const GEOFENCING_TASK_B = “geofencing-task-B”;

export const defineGeofencingTasks = () => {
TaskManager.defineTask(
GEOFENCING_TASK_NAME_A,
async ({ data: { eventType, region }, error }) => {
if (error) {
console.log(error);
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
console.log(“enter - Task A”);
} else if (eventType === Location.GeofencingEventType.Exit) {
console.log(“exit - Task A”);
}
}
);

TaskManager.defineTask(
GEOFENCING_TASK_NAME_B,
async ({ data: { eventType, region }, error }) => {
if (error) {
console.log(error);
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
console.log(“enter - Task B”);
} else if (eventType === Location.GeofencingEventType.Exit) {
console.log(“exit - Task B”);
}
}
);
};

and executing defineGeofencingTasks()
in App.js before export default function App() {…}.

The geofences are then registered by running
Location.startGeofencingAsync(GEOFENCING_TASK_A, geofenceArray_A)
Location.startGeofencingAsync(GEOFENCING_TASK_B, geofenceArray_B)

the outcome is that for every geofence event (entry or exit for geofenceArray_A) GEOFENCING_TASK_A and GEOFENCING_TASK_B are both executed.
(for example for entry event in geofenceArray_A the console will log
“enter - Task A”
“enter - Task B”
).

hm, that is definitely odd and not expected behavior :thinking: and it sounds simple enough that it should be working. This is on both iOS and Android?

could you put together a snack that reproduces that behavior? then we can open up a bug report

Thanks for the step by step tutorial. This works really well for us, thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.