Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to effectively remove geofences #1994

Closed
chris-eaheart opened this issue Apr 12, 2024 · 8 comments
Closed

Unable to effectively remove geofences #1994

chris-eaheart opened this issue Apr 12, 2024 · 8 comments

Comments

@chris-eaheart
Copy link

chris-eaheart commented Apr 12, 2024

  • Plugin version: 4.16.0
  • Platform: Android
  • OS version: 14
  • Device manufacturer / model: Pixel 7a
  • React Native version (react-native -v): 0.73.2
  • Plugin config
BackgroundGeolocation.ready({
            desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
            distanceFilter: 10,
            stopTimeout: 5,           // Activity Recognition
            stopOnTerminate: false,   // Application config: Allow the background-service to continue tracking when user closes the app.
            startOnBoot: true,        // Application config: Auto start tracking when device is powered-up.

            // Debugging options
            debug: false,
        })
        .then((state) => {
            BackgroundGeolocation.start();
        })
        .catch(err => {
            console.error('Failed to start location services:', err);
            crashlytics().recordError(err);
        });

BackgroundGeolocation.onGeofence(geofence => {
            //console.log("[geofence] ", geofence);
            BackgroundGeolocation.removeGeofences().then(success => {
                //console.log('[removeGeofences] all geofences have been destroyed');
            });
        });

        BackgroundGeolocation.onGeofencesChange(geofence => {
            // console.log("[geofence] ", geofence);
            BackgroundGeolocation.removeGeofences().then(success => {
                // console.log('[removeGeofences] all geofences have been destroyed');
            });
        });

Expected Behavior

Geofences should not be created, and tracking should always pick up my latest location.

Actual Behavior

Geofences are being created - tracking is delayed until I move outside of the geofenced area.

Chris, just will refer you to your feedback from this issue: #833

You said if you do not want to track geofences, to remove them. I am removing them above in two events that seem most logical to remove them, but I am finding that geofences are still being created.

I am using your sample app on a physical device, and have modified the code as indicated above. The below is a walk I took just this morning - the red line indicates that initial part of that walk that was not tracked.

image

@christocracy
Copy link
Member

Are you actually creating geofences (with .addGeofence)?

@chris-eaheart
Copy link
Author

chris-eaheart commented Apr 12, 2024 via email

@christocracy
Copy link
Member

I am not calling addGeofence

Then you have no reason to expect .removeGeofences to do anything.

@christocracy
Copy link
Member

And you have no reason to listen to . onGeofence Or .onGeofencesChange

@chris-eaheart
Copy link
Author

Ok, then the issue title doesn't accurately reflect the issue I'm having - I will close this issue and start a new one.

@christocracy
Copy link
Member

The plug-in does use an internal “stationary geofence” around the last known position, the exit of which signals that the device is moving. This geofence is crucial to the plug-in’s philosophy of operation. Particularly so since the Play Store has become very strict with allowing the motion api to launch foreground-services in the background.

This “stationary geofence” is what allows this plug-in to launch a foreground-service in the background and resume tracking. Android 14 has become very strict about when foreground-services can be launched.

@chris-eaheart
Copy link
Author

Ok, that is helpful, and that is what I was referring to - so it is not possible to remove this, or reduce the size of it at least? I just want to get a bit more accuracy with the app I'm developing, and I'm finding this internal geofence to be limiting my ability to have the desired accuracy.

@christocracy
Copy link
Member

so it is not possible to remove this,

if you were able to “remove” the stationary geofence, nothing would work. Your app would lie dormant, suspended in the background.

or reduce the size of it at least?

The OS doesn’t respond to any geofence radius < ~200 meters. The plug-in applies a radius of 150. If you were to set a radius: 0, the OS would still only respond as if you set it to 200.

Geofences are monitored by the OS.

you are always free to manually engage tracking by calling .changePace(true) while your app is in the foreground, like a “Jogging App” with its [Start Workout] button.

We’re fortunate the OS continues to allow geofences to initiate location-tracking in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants