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.54k stars 424 forks source link

Unable to effectively remove geofences #1994

Closed chris-eaheart closed 1 month ago

chris-eaheart commented 1 month ago
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: https://github.com/transistorsoft/react-native-background-geolocation/issues/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 commented 1 month ago

Are you actually creating geofences (with .addGeofence)?

chris-eaheart commented 1 month ago

I am not calling addGeofence anywhere in the code.

christocracy commented 1 month ago

I am not calling addGeofence

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

christocracy commented 1 month ago

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

chris-eaheart commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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.