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.63k stars 426 forks source link

Frequently received location on headless task #458

Closed atifaziz1 closed 6 years ago

atifaziz1 commented 6 years ago

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

christocracy commented 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.

yo2rk commented 4 years ago

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.

christocracy commented 4 years ago

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.

yo2rk commented 4 years ago

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 ] 07-08 19:07:30.953 18835 18926 I TSLocationManager: ✅ Google Play Services: connected (version code:12451000) 07-08 19:07:30.963 18835 18933 D TSLocationManager: [c.t.l.l.TSLocationManager$d run] 07-08 19:07:30.963 18835 18933 D TSLocationManager: ℹ️ Load last odometer location: Location[TSLocationManager acc=13 t=?!? et=?!? {Bundle[{odometer=0.0}]}] 07-08 19:07:30.963 18835 18926 D TSLocationManager: [c.t.l.http.HttpService startMonitoringConnectivityChanges] 07-08 19:07:30.963 18835 18926 D TSLocationManager: 🎾 Start monitoring connectivity changes 07-08 19:07:30.973 18835 18934 D TSLocationManager: [c.t.l.data.sqlite.b prune] 07-08 19:07:30.973 18835 18934 D TSLocationManager: ℹ️ PRUNE -1 days 07-08 19:07:30.993 18835 18938 D TSLocationManager: [c.t.l.http.HttpService a] 07-08 19:07:30.993 18835 18938 D TSLocationManager: ╔═════════════════════════════════════════════ 07-08 19:07:30.993 18835 18938 D TSLocationManager: ║ 📶 Connectivity change: connected? true 07-08 19:07:30.993 18835 18938 D TSLocationManager: ╠═════════════════════════════════════════════ 07-08 19:07:31.013 18835 18926 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO 07-08 19:07:31.023 18835 18835 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO 07-08 19:07:31.023 18835 18926 I TSLocationManager: [c.t.l.s.ActivityRecognitionService b] 07-08 19:07:31.023 18835 18926 I TSLocationManager: 🎾 Start motion-activity updates 07-08 19:07:31.023 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask onHeadlessEvent] 💀 event: connectivitychange 07-08 19:07:31.023 18835 18926 I TSLocationManager: [c.t.l.a.BackgroundGeolocation f] 07-08 19:07:31.023 18835 18926 I TSLocationManager: 🎾 Start monitoring location-provider changes 07-08 19:07:31.033 18835 18926 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO 07-08 19:07:31.053 18835 18835 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO 07-08 19:07:31.053 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask onHeadlessEvent] 💀 event: providerchange 07-08 19:07:31.073 18835 18878 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO 07-08 19:07:31.073 18835 18926 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO 07-08 19:07:31.083 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask onHeadlessEvent] 💀 event: terminate 07-08 19:07:31.263 18835 18835 D TSLocationManager: [c.t.l.s.ActivityRecognitionService a] 07-08 19:07:31.263 18835 18835 D TSLocationManager: 🚘 ️DetectedActivity [type=STILL, confidence=100] 07-08 19:07:31.363 18835 18835 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO 07-08 19:07:31.363 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask onHeadlessEvent] 💀 event: activitychange 07-08 19:07:31.363 18835 18835 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a] 07-08 19:07:31.363 18835 18835 I TSLocationManager: ╔═════════════════════════════════════════════ 07-08 19:07:31.363 18835 18835 I TSLocationManager: ║ Motion Transition Result 07-08 19:07:31.363 18835 18835 I TSLocationManager: ╠═════════════════════════════════════════════ 07-08 19:07:31.363 18835 18835 I TSLocationManager: ╟─ 🎾 ENTER: still 07-08 19:07:31.363 18835 18835 I TSLocationManager: ╚═════════════════════════════════════════════ 07-08 19:07:31.623 18835 18835 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy] 07-08 19:07:31.623 18835 18835 D TSLocationManager: 🔴 ActivityRecognitionService destroyed 07-08 19:07:34.193 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask$2 onHeadlessJsTaskStart] taskId: 1 07-08 19:07:34.203 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask$2 onHeadlessJsTaskStart] taskId: 2 07-08 19:07:34.203 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask$2 onHeadlessJsTaskStart] taskId: 3 07-08 19:07:34.203 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask$2 onHeadlessJsTaskStart] taskId: 4 07-08 19:07:38.103 18835 18935 D TSLocationManager: [c.t.locationmanager.util.b b] 07-08 19:07:38.103 18835 18935 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted 07-08 19:07:38.113 18835 18935 D TSLocationManager: [c.t.locationmanager.util.b b] 07-08 19:07:38.113 18835 18935 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted 07-08 19:07:38.133 18835 18934 D TSLocationManager: [c.t.locationmanager.util.b b] 07-08 19:07:38.133 18835 18934 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted 07-08 19:07:38.143 18835 18932 D TSLocationManager: [c.t.locationmanager.util.b b] 07-08 19:07:38.143 18835 18932 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted 07-08 19:07:38.223 18835 18934 I TSLocationManager: [c.t.l.s.LocationRequestService b] 07-08 19:07:38.223 18835 18934 I TSLocationManager: ╔═════════════════════════════════════════════ 07-08 19:07:38.223 18835 18934 I TSLocationManager: ║ getCurrentPosition LocationResult: 1 07-08 19:07:38.223 18835 18934 I TSLocationManager: ╠═════════════════════════════════════════════ 07-08 19:07:38.223 18835 18934 I TSLocationManager: ╟─ 📍 Location[fused acc=14 et=+3h51m31s637ms alt=884.7999877929688 {Bundle[mParcelledData.dataSize=52]}], age: 71ms, time: 1594224458157 07-08 19:07:38.233 18835 18934 I TSLocationManager: [c.t.l.g.TSGeofenceManager start] 07-08 19:07:38.233 18835 18934 I TSLocationManager: 🎾 Start monitoring geofences 07-08 19:07:38.243 18835 18934 I TSLocationManager: [c.t.l.l.TSLocationManager onSingleLocationResult] 07-08 19:07:38.243 18835 18934 I TSLocationManager: 🔵 Acquired current position 07-08 19:07:38.253 18835 18934 D TSLocationManager: [c.t.l.l.TSLocationManager calculateMedianAccuracy] Median accuracy: 13.693 07-08 19:07:38.263 18835 18835 D TSLocationManager: [c.t.l.s.LocationRequestService onDestroy] 07-08 19:07:38.303 18835 18835 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO 07-08 19:07:38.303 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask onHeadlessEvent] 💀 event: location 07-08 19:07:38.313 18835 18934 D TSLocationManager: [c.t.l.s.LocationRequestService b] SingleLocationRequest 1 isFinished? true 07-08 19:07:38.323 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask$2 onHeadlessJsTaskStart] taskId: 5 07-08 19:07:38.323 18835 18933 D TSLocationManager: [c.t.locationmanager.util.b b] 07-08 19:07:38.323 18835 18933 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted 07-08 19:07:38.343 18835 18835 D TSLocationManager: [c.t.r.HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 1 07-08 19:07:38.493 18835 18942 I TSLocationManager: [c.t.l.s.LocationRequestService a] 07-08 19:07:38.493 18835 18942 I TSLocationManager: ℹ️ Location availability: true 07-08 19:07:38.503 18835 18942 I TSLocationManager: [c.t.l.s.LocationRequestService a] 07-08 19:07:38.503 18835 18942 I TSLocationManager: ℹ️ Location availability: true 07-08 19:07:38.523 18835 18934 I TSLocationManager: [c.t.l.s.LocationRequestService a] 07-08 19:07:38.523 18835 18934 I TSLocationManager: ℹ️ Location availability: true 07-08 19:07:38.543 18835 18942 I TSLocationManager: [c.t.l.s.LocationRequestService b] 07-08 19:07:38.543 18835 18942 I TSLocationManager: ╔═════════════════════════════════════════════ 07-08 19:07:38.543 18835 18942 I TSLocationManager: ║ getCurrentPosition LocationResult: 3 07-08 19:07:38.543 18835 18942 I TSLocationManager: ╠═════════════════════════════════════════════ 07-08 19:07:38.543 18835 18942 I TSLocationManager: ╟─ 📍 Location[fused acc=14 et=+3h51m32s3ms alt=884.7999877929688 {Bundle[mParcelledData.dataSize=52]}], age: 28ms, time: 1594224458523 07-08 19:07:38.553 18835 18942 I TSLocationManager: [c.t.l.l.TSLocationManager onSingleLocationResult] 07-08 19:07:38.553 18835 18942 I TSLocationManager: 🔵 Acquired current position 07-08 19:07:38.553 18835 18934 I TSLocationManager: [c.t.l.s.LocationRequestService b] 07-08 19:07:38.553 18835 18934 I TSLocationManager: ╔═════════════════════════════════════════════ 07-08 19:07:38.553 18835 18934 I TSLocationManager: ║ getCurrentPosition LocationResult: 2 07-08 19:07:38.553 18835 18934 I TSLocationManager: ╠═════════════════════════════════════════════ 07-08 19:07:38.553 18835 18934 I TSLocationManager: ╟─ 📍 Location[fused acc=14 et=+3h51m32s3ms alt=884.7999877929688 {Bundle[mParcelledData.dataSize=52]}], age: 37ms, time: 1594224458523 07-08 19:07:38.553 18835 18942 D TSLocationManager: [c.t.l.l.TSLocationManager calculateMedianAccuracy] Median accuracy: 13.693 07-08 19:07:38.563 18835 18935 I TSLocationManager: [c.t.l.s.LocationRequestService b]

christocracy commented 4 years ago

You are likely “shooting yourself in the foot” in your Headless-task, by calling getCurrentPosition.

Show me your headless-task code.

yo2rk commented 4 years ago
  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..

christocracy commented 4 years ago

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.

BTW, 'heartbeat' is never called

Yes, because you've not configured a heartbeatInterval:

heartbeatInterval": -1,
yo2rk commented 4 years ago

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.
christocracy commented 4 years ago

Docs are wrong.