Trying to get Location.startGeofencingAsync to work...

Has anyone had any luck with getting geofencing working.
I updated to SDK 32 got Location.startLocationUpdatesAsync working, but no luck with geofencing.

Here’s my code:

Setup task in the TaskManager

TaskManager.defineTask(‘GEO_TRACK_LOCATION’, ({ data: { eventType, region }, error }) => {
if (error) {
console.log(‘GEO_TRACK_LOCATION - ERROR’, { error });
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
console.log(“GEO_TRACK_LOCATION - ENTER”, { eventType, region });
} else if (eventType === Location.GeofencingEventType.Exit) {
console.log(“GEO_TRACK_LOCATION - EXIT”, { eventType, region});
}
});

Registering the task.
Location.startGeofencingAsync(‘GEO_TRACK_LOCATION’, [
{
identifier: ‘1’,
latitude: 34.17,
longitude: -118.40,
radius: 50,
notifyOnEnter: true,
notifyOnExit: true,
}]
);

My infoPlist is
“infoPlist”: {
“UIBackgroundModes”: [“location”],
}

When I try it in the emulator, I immediately get the Exit event and then nothing.
When I try it in TestFlight - nothing, no events are ever fired, no matter where I am located.

Does anyone have a working example?

Did you grant location permission?

Yes, I was able to get startLocationUpdatesAsync to work which also needs location permissions and runs in the background. However, startGeofencingAsync - no luck.

I think a factor may be that your lat/long is far too imprecise - the lat/longs I give the geofence are ~14 decimal places. Not saying it has to be that precise, but you want at least 3 decimal places: Measuring accuracy of latitude and longitude? - Geographic Information Systems Stack Exchange

That said, I have gotten geofencing to fire entry/exit but only when the app is running, and only on the client.

1 Like

Those are actually changed/“obfuscated” :slight_smile: lat/long (didn’t want to publish the actual place I was testing with).
I did use 6-8 decimal places with no luck, should maybe try to get more precise and see what happens.

Anything over 5 decimal places is basically redundant because 5 decimal places is already down to roughly a meter

1 Like

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