Closed atifaziz1 closed 6 years ago
It's a bad idea to use time-based tracking. It consumes more battery. By default, the plugin is distance-based (ie: distanceFilter
). The plugin will record a location every time the device moves distanceFilter
meters.
I am having the same problem. Here is my BackgroundGeolocation configuration:
BackgroundGeolocation.ready({
enableHeadless: true,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 50,
stopTimeout: 1,
debug: false,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false,
startOnBoot: true,
}
I am getting location events constantly (even when device is still), which look like that:
[BackgroundGeolocation HeadlessTask] -', 'location', { extras: {},
│ activity: { confidence: 100, type: 'still' },
│ odometer: 0,
│ battery: { level: 1, is_charging: true },
│ timestamp: '2020-07-08T12:14:10.598Z',
│ coords:
│ { altitude: 860.1,
│ heading: 280.08,
│ speed: 1.03,
│ accuracy: 34.3,
│ longitude: <my longitude>,
│ latitude: <my latitude> },
│ uuid: '80016919-8087-4891-904a-747ca350b975',
└ is_moving: false }
Am I supposed to configure my ' BackgroundGeolocation.registerHeadlessTask(HeadlessTask) ' specificaly or does it have the same configuration settings as BackgroundGeolocation.ready()? If yes, how should I do it?
Thanks!
Edit:
The same thing happens also when I changed the configuration to:
distanceFilter: 0,
locationUpdateInterval:1000*30,
deferTime: 1000 * 30,
I still get bombarded by a lot of locations events at once when I am terminating the app.
or does it have the same configuration settings as BackgroundGeolocation.ready()
Yes it has the same config.
Are you observing the plugin logs in adb logcat
? See Wiki Debugging.
Thank you for the quick reply!
Here is some of my adb logacat (it just get repeated endlessly after that):
07-08 19:07:30.913 18835 18926 I TSLocationManager: ╔═════════════════════════════════════════════
07-08 19:07:30.913 18835 18926 I TSLocationManager: ║ TSLocationManager version: 3.1.5 (361)
07-08 19:07:30.913 18835 18926 I TSLocationManager: ╠═════════════════════════════════════════════
07-08 19:07:30.913 18835 18926 I TSLocationManager: ╟─ samsung SM-G900F @ 6.0.1 (react-native)
07-08 19:07:30.913 18835 18926 I TSLocationManager: {
07-08 19:07:30.913 18835 18926 I TSLocationManager: "activityRecognitionInterval": 10000,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "allowIdenticalLocations": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "authorization": {},
07-08 19:07:30.913 18835 18926 I TSLocationManager: "autoSync": true,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "autoSyncThreshold": 0,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "batchSync": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "configUrl": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "debug": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "deferTime": 30000,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "desiredAccuracy": -1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "desiredOdometerAccuracy": 100,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "disableAutoSyncOnCellular": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "disableElasticity": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "disableLocationAuthorizationAlert": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "disableMotionActivityUpdates": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "disableStopDetection": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "distanceFilter": 0,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "elasticityMultiplier": 1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "enableHeadless": true,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "enableTimestampMeta": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "encrypt": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "extras": {},
07-08 19:07:30.913 18835 18926 I TSLocationManager: "fastestLocationUpdateInterval": -1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "forceReloadOnBoot": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "forceReloadOnGeofence": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "forceReloadOnHeartbeat": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "forceReloadOnLocationChange": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "forceReloadOnMotionChange": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "forceReloadOnSchedule": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "foregroundService": true,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "geofenceInitialTriggerEntry": true,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "geofenceModeHighAccuracy": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "geofenceProximityRadius": 1000,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "geofenceTemplate": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "headers": {},
07-08 19:07:30.913 18835 18926 I TSLocationManager: "headlessJobService": "com.transistorsoft.rnbackgroundgeolocation.HeadlessTask",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "heartbeatInterval": -1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "httpRootProperty": "location",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "httpTimeout": 60000,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "isMoving": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "locationAuthorizationRequest": "Always",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "locationTemplate": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "locationTimeout": 60,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "locationUpdateInterval": 30000,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "locationsOrderDirection": "ASC",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "logLevel": 5,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "logMaxDays": 3,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "maxBatchSize": -1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "maxDaysToPersist": 1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "maxRecordsToPersist": -1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "method": "POST",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "minimumActivityRecognitionConfidence": 75,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "motionTriggerDelay": 0,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "notification": {
07-08 19:07:30.913 18835 18926 I TSLocationManager: "layout": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "title": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "text": "Location Service activated",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "color": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "channelName": "TSLocationManager",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "smallIcon": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "largeIcon": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "priority": 0,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "strings": {},
07-08 19:07:30.913 18835 18926 I TSLocationManager: "actions": []
07-08 19:07:30.913 18835 18926 I TSLocationManager: },
07-08 19:07:30.913 18835 18926 I TSLocationManager: "params": {},
07-08 19:07:30.913 18835 18926 I TSLocationManager: "persist": true,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "persistMode": 2,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "schedule": [],
07-08 19:07:30.913 18835 18926 I TSLocationManager: "scheduleUseAlarmManager": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "speedJumpFilter": 300,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "startOnBoot": true,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "stationaryRadius": 25,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "stopAfterElapsedMinutes": 0,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "stopOnStationary": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "stopOnTerminate": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "stopTimeout": 1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "url": "",
07-08 19:07:30.913 18835 18926 I TSLocationManager: "useSignificantChangesOnly": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "enabled": true,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "schedulerEnabled": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "trackingMode": 1,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "odometer": 0,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "isFirstBoot": false,
07-08 19:07:30.913 18835 18926 I TSLocationManager: "didLaunchInBackground": false
07-08 19:07:30.913 18835 18926 I TSLocationManager: }
07-08 19:07:30.923 18835 18926 I TSLocationManager: [c.t.l.adapter.TSConfig print]
07-08 19:07:30.923 18835 18926 I TSLocationManager: ╔═════════════════════════════════════════════
07-08 19:07:30.923 18835 18926 I TSLocationManager: ║ DEVICE SENSORS
07-08 19:07:30.923 18835 18926 I TSLocationManager: ╠═════════════════════════════════════════════
07-08 19:07:30.923 18835 18926 I TSLocationManager: ╟─ ✅ ACCELEROMETER: {Sensor name="MPU6500 Acceleration Sensor", vendor="Invensense", version=1, type=1, maxRange=19.6133, resolution=5.985504E-4, power=0.25, minDelay=5000}
07-08 19:07:30.923 18835 18926 I TSLocationManager: ╟─ ✅ GYROSCOPE: {Sensor name="MPU6500 Gyroscope Sensor", vendor="Invensense", version=1, type=4, maxRange=34.906586, resolution=0.0010652645, power=6.1, minDelay=5000}
07-08 19:07:30.923 18835 18926 I TSLocationManager: ╟─ ✅ MAGNETOMETER: {Sensor name="AK09911C Magnetic field Sensor", vendor="Asahi Kasei Microdevices", version=1, type=2, maxRange=2000.0, resolution=0.06, power=6.0, minDelay=10000}
07-08 19:07:30.923 18835 18926 I TSLocationManager: ╟─ ✅ SIGNIFICANT_MOTION: {Sensor name="SAMSUNG Significant Motion Sensor", vendor="Samsung Inc.", version=2, type=17, maxRange=1.0, resolution=1.0, power=0.3, minDelay=-1}
07-08 19:07:30.923 18835 18926 I TSLocationManager: ╚═════════════════════════════════════════════
07-08 19:07:30.953 18835 18926 I TSLocationManager: [c.t.l.a.BackgroundGeolocation
You are likely “shooting yourself in the foot” in your Headless-task, by calling getCurrentPosition.
Show me your headless-task code.
let HeadlessTask = async (event) => {
let params = event.params;
console.log('[BackgroundGeolocation HeadlessTask] -', event.name, params);
let location = await getCurrentPosition();
await console.log('location is : ')
await console.log(location);
switch (event.name) {
case 'heartbeat':
console.log('heartbeat');
// Use await for async tasks
getGeoFireLocations(location.coords.latitude,location.coords.longitude)
console.log('[BackgroundGeolocation HeadlessTask] - getCurrentPosition:', location);
break;
case 'motionchange':
console.log('motionchange');
// Use await for async tasks
let location1 = await getCurrentPosition();
getGeoFireLocations(location1.coords.latitude,location1.coords.longitude)
console.log('[BackgroundGeolocation HeadlessTask] - getCurrentPosition:', location);
break;
case 'location':
console.log('location');
// Use await for async tasks
getGeoFireLocations(location.coords.latitude,location.coords.longitude)
console.log('[BackgroundGeolocation HeadlessTask] - getCurrentPosition:', location);
break;
}
}
BTW, 'heartbeat' is never called (tried using heartbeat alone before adding getCurrentPosition). getGeoFireLocations() calles a geoFire function (which execure a geoQuery function) if this info helps in any way..
Yes, you are "shooting yourself in the foot". You have to be aware that calling getCurrentPosition
generates a headless location
event. You have created an infinite loop.
getCurrentPosition
within one of your switch case
case 'location'
must NEVER cause the plugin to generate a location
event.BTW, 'heartbeat' is never called
Yes, because you've not configured a heartbeatInterval
:
heartbeatInterval": -1,
Thank you very much, appreciate this, it all works well now.
Regards the heartbeat, it too works well. I thought that the default value is 60 so I didn't write anything in .ready() .
heartbeatInterval | Integer | Default: 60. Rate in seconds to fire BackgroundGeolocation.onHeartbeat events. |
---|
Docs are wrong.
I am getting location frequently in headless task.How to get location after specific interval of time?
Plugin version: 2.11.0 Platform: Android OS version: Lollypop Device manufacturer / model: Motorola / moto G React Native version : 0.50.4