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

Android Location Update Interval Not Consistent #2252

Open
sudesh-kumar-cse opened this issue Jan 16, 2025 · 2 comments
Open

Android Location Update Interval Not Consistent #2252

sudesh-kumar-cse opened this issue Jan 16, 2025 · 2 comments
Labels

Comments

@sudesh-kumar-cse
Copy link

sudesh-kumar-cse commented Jan 16, 2025

Your Environment

  • Plugin version: 4.18.3
  • Platform: Android
  • OS version: Android 14
  • Device manufacturer / model: Oneplus Nord CE3 LITE
  • React Native version (react-native -v): 0.73.1
  • Plugin config
try {
            const state = await BackgroundGeolocation.ready({

                // Core location settings
                desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
                distanceFilter: 0,
                locationUpdateInterval: 60000,
                fastestLocationUpdateInterval: 60000,
                locationTimeout: 30,

                // Background behavior
                stopOnTerminate: true,
                startOnBoot: false,



                // Foreground behavior
                foregroundService: true,
                notification: {
                    title: "Location Service",
                    text: "Location tracking is active",
                    channelId: "location",
                    channelName: "TSLocationManager",
                    icon: "ic_launcher",
                    sticky: true,
                    priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_HIGH
                },
                enableHeadless: false,

                // Sync and storage settings
                autoSync: true,
                maxRecordsToPersist: 1,
                persistMode: BackgroundGeolocation.PERSIST_MODE_NONE,


                // Motion and battery settings
                disableStopDetection: true,
                pausesLocationUpdatesAutomatically: false,
                allowIdenticalLocations: true,

                // Heartbeat configuration
                heartbeatInterval: 60,

                // iOS specific settings
                preventSuspend: true,
                locationAuthorizationRequest: 'WhenInUse',
                activityType: BackgroundGeolocation.ACTIVITY_TYPE_OTHER,
                showsBackgroundLocationIndicator: false,
                disableLocationAuthorizationAlert: true,
                disableMotionActivityUpdates: true,

                // Debug settings
                debug: false,

            });

            if (!state.enabled && !isBackgroundLocationService) {
                isBackgroundLocationService = true;
                await BackgroundGeolocation.start();
            }
        } catch (error) {
        }
        
        
        BackgroundGeolocation.onLocation(async (location) => {
            console.log('====================================');
            console.log('LOCATION LISTNER', '\n', new Date().toString(), '\n', location?.coords);
        });
        
        BackgroundGeolocation.onHeartbeat(async () => {
            try {
                const location = await BackgroundGeolocation.getCurrentPosition({
                    samples: 1,
                    persist: false,
                    timeout: 30,
                    maximumAge: 5000,
                    desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH
                });
               console.log('====================================');
             console.log('HEARTBEAT LISTNER', '\n', new Date().toString(), '\n', location?.coords);
            } catch (error) {
                // Try to restart tracking on error
                try {
                    const state = await BackgroundGeolocation.getState();
                    if (!state.enabled) {
                        await BackgroundGeolocation.start();
                    }
                } catch (restartError) {
                }
            }
        });

Expected Behavior

The library should return the location every 1 minute on both Android and iOS, as per the configuration.

Actual Behavior

The location updates are working fine on iOS, as expected every minute. However, on Android, the updates are inconsistent, sometimes occurring at intervals of 40 seconds, 1.5 minutes, 2 minutes, or even longer.

@christocracy
Copy link
Member

The location updates are working fine on iOS, as expected every minute.

iOS does not do time-based location-updates -- it strictly uses distance-based updates with distanceFilter.

However, on Android, the updates are inconsistent, sometimes occurring at intervals of 40 seconds, 1.5 minutes, 2 minutes, or even longer.

Android provides no guarantee that a location will be provided exactly every locationUpdateInterval.

Copy link

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

@github-actions github-actions bot added the stale label Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants