transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.66k stars 426 forks source link

DWELL / loiteringDelay is not detected for Polygon Geofences IOS #2121

Closed sirusbaladi closed 1 month ago

sirusbaladi commented 3 months ago

Your Environment

Expected Behavior

When I go into a polygon geofence I should receive geofence: DWELL

Actual Behavior

I do receive geofence: DWELL for my radius geofences.

For polygon Geofences it only detecs enter / exit.

Steps to Reproduce

  1. add a polygon geofence
  2. walk in it
  3. I'm using debug mode with no license in expo.
christocracy commented 3 months ago

DWELL / loiteringDelay

It’s not implemented yet.

sirusbaladi commented 3 months ago

DWELL / loiteringDelay

It’s not implemented yet.

Any timeline?

We are launching the app this saturday and I was convinced that polygon geofence had dwell. It's a core feature.

christocracy commented 3 months ago

Any timeline?

No. This winter perhaps.

christocracy commented 3 months ago

You’re free to run your own timers in the onGeofence enter event.

sirusbaladi commented 3 months ago

You’re free to run your own timers in the onGeofence enter event.

Would you say something like this will work? In the if statement with event.vertices to make it happen only for polygon geofences.

I wonder if an 8 minutes times is okay.

BackgroundGeolocation.onGeofence((event) => {
  if (event.action === "ENTER" && event.vertices) {
    BackgroundGeolocation.startBackgroundTask().then((taskId) => {
      setTimeout(() => {
        console.log("DWELL");
        BackgroundGeolocation.stopBackgroundTask(taskId);
      }, 8 * 60 * 1000); // 8 minutes in milliseconds
    }).catch((error) => {
      console.error("Error starting background task:", error);
    });
  }
});
sirusbaladi commented 3 months ago

or do you have a better way while waiting for the proper plugin implementation?

christocracy commented 3 months ago

You should keep a reference to your timerId so you can cancel it if EXIT occurs before timer expires. You’d need to keep a Hash of timers keyed on geofence.identifier.

8 min is kind of long.

const timerId = setTimeout(…)
DWELL_TIMERS[identifer] = timerId
sirusbaladi commented 3 months ago

I see, thank you.

But I wonder if this will work at all. In the documentation it says that startBackgroundTask() will only work for 180 seconds and my timer is 8 minutes.

For non polygon geofences setting loiteringDelay to 8 minutes works great and never failed but I suspect it uses a different mechanism

christocracy commented 3 months ago

When the plug-in enters the containing geofence of a polygon, it turns ON location-services.

when location-services are ON, your app is completely alive in the background, just as if it were in the foreground.

there’s no need for background-tasks.

sirusbaladi commented 3 months ago

When the plug-in enters the containing geofence of a polygon, it turns ON location-services.

when location-services are ON, your app is completely alive in the background, just as if it were in the foreground.

there’s no need for background-tasks.

even if .startGefence?

christocracy commented 2 months ago

even if .startGefence?

Yes. But since I've been working on polygon-geofencing for the last week+, I've decided to implement notifyOnDwell for polygon geofences.

sirusbaladi commented 2 months ago

even if .startGefence?

Yes. But since I've been working on polygon-geofencing for the last week+, I've decided to implement notifyOnDwell for polygon geofences.

oh awesome! and is this already released? how to get it?

christocracy commented 2 months ago

I’ll let you know when it’s pushed to the private repo.

christocracy commented 2 months ago

See #2113 (this comment)

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 14 days since being marked as stale.