react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Location updates are not working properly (getting 20–25 locations in a minute, even on high speed)
Your Environment
- Plugin version: 4.16.5
- Platform: iOS
- OS version: 17.5.1
- Device manufacturer / model: IPhone 14 Pro Max
- React Native version (
react-native -v): 0.70.6 - Plugin config
BackgroundGeolocation.ready({
debug: false,
locationAuthorizationRequest: 'Always',
showsBackgroundLocationIndicator: false,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
desiredAccuracy: desiredAccuracy
? desiredAccuracy
: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: distanceFilter ? distanceFilter : 10,
stopOnTerminate: false,
disableMotionActivityUpdates: true,
startOnBoot: true,
heartbeatInterval: 10,
enableHeadless: true,
locationAuthorizationAlert: {
titleWhenNotEnabled: t('title_when_not_enabled'),
titleWhenOff: t('title_when_off'),
instructions: t('location_auth_alert_instructions'),
cancelButton: t('location_auth_alert_cancel'),
settingsButton: t('location_auth_alert_settings'),
},
stopTimeout: 5,
desiredOdometerAccuracy: 10,
backgroundPermissionRationale: {
title: 'Allow "App" to use your location?',
message:
'Please select "Change to Always Allow" below so App can access your location
even when you are not using the app.',
positiveAction: 'Change to "Always Allow"',
negativeAction: 'Cancel',
},
})
.then((state) => {
if (!state.enabled) {
return BackgroundGeolocation.start()
.then(() => payload)
.catch((error) => Promise.reject(JSON.stringify(error)));
}
})
.catch((err) => {
console.error('Background Geop Location Error : ', err);
});
Expected Behavior
- Low Battery Drain using above Plugin config Settings.
- I have also mentioned the above IOS Version and Device that I am using & also the config settings of plugin.
Actual Behavior
I am using the above settings and getting much battery drain, specially on IOS Devices. Moreover, plugin is giving me constantly location updates, e.g. 20-25 location updates in one minutes I have shared a Excel sheet with speed and location with respect to time.
Steps to Reproduce
1.Set the above configuration and you will see the same behaviour as described above. 2. 3. 4.
Context
Debug logs
Logs
``` { activityRecognitionInterval = 10000; activityType = 1; authorization = { }; autoSync = 1; autoSyncThreshold = 0; batchSync = 0; debug = 0; desiredAccuracy = "-1"; desiredOdometerAccuracy = 10; didDeviceReboot = 0; didLaunchInBackground = 0; didRequestUpgradeLocationAuthorization = 1; disableAutoSyncOnCellular = 0; disableElasticity = 0; disableLocationAuthorizationAlert = 0; disableMotionActivityUpdates = 1; disableStopDetection = 0; distanceFilter = 9; elasticityMultiplier = 1; enableTimestampMeta = 0; enabled = 1; extras = { }; geofenceInitialTriggerEntry = 1; geofenceProximityRadius = 2000; geofenceTemplate = ""; headers = { }; heartbeatInterval = 60; httpRootProperty = location; httpTimeout = 60000; iOSHasWarnedLocationServicesOff = 0; isFirstBoot = 0; isMoving = 0; lastLocationAuthorizationStatus = 3; locationAuthorizationAlert = { cancelButton = Cancel; instructions = "To use background location, you must enable 'Always' in the Location Services settings"; settingsButton = Settings; titleWhenNotEnabled = "Location Services are Disabled"; titleWhenOff = "Location Services are OFF"; }; locationAuthorizationRequest = Always; locationTemplate = ""; locationTimeout = 60; locationsOrderDirection = ASC; logLevel = 5; logMaxDays = 3; maxBatchSize = "-1"; maxDaysToPersist = 1; maxRecordsToPersist = "-1"; method = POST; minimumActivityRecognitionConfidence = 70; odometer = "219499.9364983908";params = { }; pausesLocationUpdatesAutomatically = 1; persistMode = 2; preventSuspend = 0; schedule = ( ); schedulerEnabled = 0; showsBackgroundLocationIndicator = 0; startOnBoot = 1; stationaryRadius = 25; stopAfterElapsedMinutes = "-1"; stopDetectionDelay = 0; stopOnStationary = 0; stopOnTerminate = 0; stopTimeout = 5; trackingMode = 1; url = ""; useSignificantChangesOnly = 0; } App Battery Drain Stats.xlsx background-geolocation (8).log location-stats(1_47pm - 4_32pm 22 aug 2024).csv
</details>
### Questions
1. What specific settings need to be configured to ensure location updates are triggered as speed changes?
2. Why plugin is draining battery highly, specially on IOS Devices.
3. What configuration changes or optimizations can be applied within the plugin settings to minimize battery usage while still maintaining adequate location tracking?
1- Why isn't the elasticity working with our current settings? 2- What steps can I take to fix the issue with elasticity? 3- Based on our current settings, what percentage of battery drain should we expect from Transistor soft during a 3-hour drive?
1- Why isn't the elasticity working with our current settings? 2- What steps can I take to fix the issue with elasticity?
It IS working, as you can clearly see in your own logs. You have a configured distanceFilter: 9 (which is really low) and the plugin is clearly scaling your distanceFilter up to 45 when travelling at 17.69 meters/second.
Search your own logs for "Updated distanceFilter"
2024-08-22 13:57:50.111
📍<+31.47439224,+74.25649331> +/- 4.75m (speed 17.69 mps / course 255.04) @ 22/08/2024, 1:57:49 PM Pakistan Standard Time
2024-08-22 13:57:50.111
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 36.0m | age: 111 ms
╚═══════════════════════════════════════════════════════════
2024-08-22 13:57:50.111 🔵-[TSLocationManager locationManager:didUpdateLocations:] Updated distanceFilter, new: 45.000000, old: 36.000000
3- Based on our current settings, what percentage of battery drain should we expect from Transistor soft during a 3-hour drive?
It will consume just as much battery as following a driving-route in any Maps app (eg: Google Maps). There is no "magic battery saving" when the plugin is in the moving state and tracking location. The battery-saving of this plugin comes in automatically turning off location-services when the device is detected to be stationary.
Are you performing your HTTP requests with each received location?
getting 20–25 locations in a minute, even on high speed
17.69 m/s = 1061.4 meters/min (17.68 * 60)
1061.4 / 45 (scaled distanceFilter)
= ~ 23 locations/min
if you want fewer locations recorded, increase your distanceFilter: 9 to something more sensible, such as 50.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.