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

BackgroundGeolocation.getCurrentPosition persistence does not write back to configured Firebase location #1997

Closed chris-eaheart closed 1 month ago

chris-eaheart commented 1 month ago

Your Environment

Plugin version: 4.16.0 Platform: Android OS version: 14 Device manufacturer / model: Pixel 7a React Native version (react-native -v): 0.73.2 Plugin config

BackgroundGeolocationFirebase.configure({
            locationsCollection: `users/${storedPhoneNumber}/locations`,
        });

        // subscribe to events
        const onLocation = BackgroundGeolocation.onLocation((location) => {
            console.log('onLocation invoked:', location.is_moving);
        });

        const subscription = BackgroundGeolocation.onHeartbeat((event) => {
            BackgroundGeolocation.getCurrentPosition({
              samples: 1,
              persist: true
            }).then((location) => {
              //console.log("[getCurrentPosition] ", location);
            });
          })

        // ready the plugin
        BackgroundGeolocation.ready({
            desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
            stationaryRadius: 25,
            heartbeatInterval: 60,
            preventSuspend: true,
            distanceFilter: 10,
            stopTimeout: 1,           // 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: true,
        })
        .then((state) => {
            BackgroundGeolocation.start();
        })
        .catch(err => {
            console.error('Failed to start location services:', err);
            crashlytics().recordError(err);
        });

Expected Behavior

BackgroundGeolocation.getCurrentPosition, with persist set to true, should write to the configured firebase location, as the firebase plugin overrides the SQLLite service.

Actual Behavior

The location document is not being written. The event is firing because I have debug set to true, and I hear the sound. The location documents are being written to firebase otherwise - it's just not working from getCurrentPosition

christocracy commented 1 month ago

Are you watching your adb logcat logs in real-time?

chris-eaheart commented 1 month ago

I spent some time trying to get anything that might be useful - this is all that I'm seeing (I added logging statements to ensure that the events were firing)


2024-04-14 20:21:14.465 15069-16241 ReactNativeJS           com.jlink                      I  '[onHeartbeat] ', { location: 
                                                                                                       { extras: {},
                                                                                                         battery: { level: 0.59, is_charging: false },
                                                                                                         activity: { confidence: 100, type: 'still' },
                                                                                                         is_moving: false,
                                                                                                         uuid: '2355fe27-4517-435d-b7a4-5b3e885d4a56',
                                                                                                         age: 129868,
                                                                                                         coords: 
                                                                                                          { age: 129890,
                                                                                                            ellipsoidal_altitude: 43.7,
                                                                                                            altitude: 43.7,
                                                                                                            altitude_accuracy: 119.2,
                                                                                                            heading_accuracy: 45,
                                                                                                            heading: 150.35,
                                                                                                            speed: 0.77,
                                                                                                            accuracy: 4.4,
                                                                                                            longitude: -77.6347413,
                                                                                                            speed_accuracy: 2.04,
                                                                                                            latitude: 37.492886 },
                                                                                                         timestamp: '2024-04-15T00:19:04.567Z',
                                                                                                         odometer: 0,
                                                                                                         event: 'heartbeat' } }
2024-04-14 20:21:14.496 15069-16241 ReactNativeJS           com.jlink                      I  'onLocation invoked:', false
2024-04-14 20:21:14.500 15069-16241 ReactNativeJS           com.jlink                      I  '[getCurrentPosition] ', { extras: {},
                                                                                                      battery: { level: 0.59, is_charging: false },
                                                                                                      activity: { confidence: 100, type: 'still' },
                                                                                                      is_moving: false,
                                                                                                      age: 129919,
                                                                                                      uuid: '4621d0c7-f9fa-485c-8dba-548742231161',
                                                                                                      odometer: 0,
                                                                                                      coords: 
                                                                                                       { age: 129925,
                                                                                                         ellipsoidal_altitude: 43.7,
                                                                                                         altitude: 43.7,
                                                                                                         altitude_accuracy: 119.2,
                                                                                                         heading_accuracy: 45,
                                                                                                         heading: 150.35,
                                                                                                         speed: 0.77,
                                                                                                         accuracy: 4.4,
                                                                                                         longitude: -77.6347413,
                                                                                                         speed_accuracy: 2.04,
                                                                                                         latitude: 37.492886 },
                                                                                                      timestamp: '2024-04-15T00:19:04.567Z' }
2024-04-14 20:21:14.903 15069-17803 TrafficStats            com.jlink                      D  tagSocket(93) with statsTag=0x90000, statsUid=-1
2024-04-14 20:21:15.380 15069-15069 MediaPlayer             com.jlink                      V  resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
christocracy commented 1 month ago

See wiki “Debugging” and api docs Config.logLevel

chris-eaheart commented 1 month ago

2024-04-14 20:40:46.167 22149-22263 ReactNativeJS           com.jlink                      I  '[onHeartbeat] ', { location: 
                                                                                                       { extras: {},
                                                                                                         battery: { level: 0.56, is_charging: false },
                                                                                                         activity: { confidence: 100, type: 'still' },
                                                                                                         is_moving: false,
                                                                                                         uuid: '157bbfad-5e94-4b9e-88eb-bfdeb6766ef4',
                                                                                                         age: 29276,
                                                                                                         coords: 
                                                                                                          { age: 29283,
                                                                                                            ellipsoidal_altitude: 48.2,
                                                                                                            altitude: 48.2,
                                                                                                            altitude_accuracy: 99.6,
                                                                                                            heading_accuracy: -1,
                                                                                                            heading: -1,
                                                                                                            speed: -1,
                                                                                                            accuracy: 100,
                                                                                                            longitude: -77.6346735,
                                                                                                            speed_accuracy: -1,
                                                                                                            latitude: 37.4929286 },
                                                                                                         timestamp: '2024-04-15T00:40:16.564Z',
                                                                                                         odometer: 0,
                                                                                                         event: 'heartbeat' } }
2024-04-14 20:40:46.188 22149-22149 TSLocationManager       com.jlink                      I  [c.t.l.l.TSLocationManager a] 
                                                                                                    ╔═════════════════════════════════════════════
                                                                                                    ║ getCurrentPosition LocationResult: 6 (29617ms old)
                                                                                                    ╠═════════════════════════════════════════════
                                                                                                    ╟─ 📍  Location[fused 37.492929,-77.634674 hAcc=100.0 et=+24m12s702ms alt=48.20000076293945 vAcc=99.57418], time: 1713141616564
2024-04-14 20:40:46.197 22149-22149 TSLocationManager       com.jlink                      I  [c.t.l.l.TSLocationManager onSingleLocationResult] 
                                                                                                      🔵  Acquired current position
2024-04-14 20:40:46.199 22149-22149 TSLocationManager       com.jlink                      D  [c.t.l.l.TSLocationManager a] Median accuracy: 45.068
2024-04-14 20:40:46.223 22149-22263 ReactNativeJS           com.jlink                      I  'onLocation invoked:', false
2024-04-14 20:40:46.231 22149-22263 ReactNativeJS           com.jlink                      I  '[getCurrentPosition] ', { extras: {},
                                                                                                      battery: { level: 0.56, is_charging: false },
                                                                                                      activity: { confidence: 100, type: 'still' },
                                                                                                      is_moving: false,
                                                                                                      age: 29640,
                                                                                                      uuid: '241cfb06-6063-4d8c-ace1-04d30229105e',
                                                                                                      odometer: 0,
                                                                                                      coords: 
                                                                                                       { age: 29650,
                                                                                                         ellipsoidal_altitude: 48.2,
                                                                                                         altitude: 48.2,
                                                                                                         altitude_accuracy: 99.6,
                                                                                                         heading_accuracy: -1,
                                                                                                         heading: -1,
                                                                                                         speed: -1,
                                                                                                         accuracy: 100,
                                                                                                         longitude: -77.6346735,
                                                                                                         speed_accuracy: -1,
                                                                                                         latitude: 37.4929286 },
                                                                                                      timestamp: '2024-04-15T00:40:16.564Z' }
2024-04-14 20:40:46.584 22149-22149 TSLocationManager       com.jlink                      I  [c.t.t.TSFirebaseProxy$4 onSuccess] 
                                                                                                      ✅  Firestore INSERT: 241cfb06-6063-4d8c-ace1-04d30229105e -> 5sYPfDasQf3eRlEiz35O
```2024-04-14 20:40:46.167 22149-22263 ReactNativeJS           com.jlink                      I  '[onHeartbeat] ', { location: 
                                                                                                       { extras: {},
                                                                                                         battery: { level: 0.56, is_charging: false },
                                                                                                         activity: { confidence: 100, type: 'still' },
                                                                                                         is_moving: false,
                                                                                                         uuid: '157bbfad-5e94-4b9e-88eb-bfdeb6766ef4',
                                                                                                         age: 29276,
                                                                                                         coords: 
                                                                                                          { age: 29283,
                                                                                                            ellipsoidal_altitude: 48.2,
                                                                                                            altitude: 48.2,
                                                                                                            altitude_accuracy: 99.6,
                                                                                                            heading_accuracy: -1,
                                                                                                            heading: -1,
                                                                                                            speed: -1,
                                                                                                            accuracy: 100,
                                                                                                            longitude: -77.6346735,
                                                                                                            speed_accuracy: -1,
                                                                                                            latitude: 37.4929286 },
                                                                                                         timestamp: '2024-04-15T00:40:16.564Z',
                                                                                                         odometer: 0,
                                                                                                         event: 'heartbeat' } }
2024-04-14 20:40:46.188 22149-22149 TSLocationManager       com.jlink                      I  [c.t.l.l.TSLocationManager a] 
                                                                                                    ╔═════════════════════════════════════════════
                                                                                                    ║ getCurrentPosition LocationResult: 6 (29617ms old)
                                                                                                    ╠═════════════════════════════════════════════
                                                                                                    ╟─ 📍  Location[fused 37.492929,-77.634674 hAcc=100.0 et=+24m12s702ms alt=48.20000076293945 vAcc=99.57418], time: 1713141616564
2024-04-14 20:40:46.197 22149-22149 TSLocationManager       com.jlink                      I  [c.t.l.l.TSLocationManager onSingleLocationResult] 
                                                                                                      🔵  Acquired current position
2024-04-14 20:40:46.199 22149-22149 TSLocationManager       com.jlink                      D  [c.t.l.l.TSLocationManager a] Median accuracy: 45.068
2024-04-14 20:40:46.223 22149-22263 ReactNativeJS           com.jlink                      I  'onLocation invoked:', false
2024-04-14 20:40:46.231 22149-22263 ReactNativeJS           com.jlink                      I  '[getCurrentPosition] ', { extras: {},
                                                                                                      battery: { level: 0.56, is_charging: false },
                                                                                                      activity: { confidence: 100, type: 'still' },
                                                                                                      is_moving: false,
                                                                                                      age: 29640,
                                                                                                      uuid: '241cfb06-6063-4d8c-ace1-04d30229105e',
                                                                                                      odometer: 0,
                                                                                                      coords: 
                                                                                                       { age: 29650,
                                                                                                         ellipsoidal_altitude: 48.2,
                                                                                                         altitude: 48.2,
                                                                                                         altitude_accuracy: 99.6,
                                                                                                         heading_accuracy: -1,
                                                                                                         heading: -1,
                                                                                                         speed: -1,
                                                                                                         accuracy: 100,
                                                                                                         longitude: -77.6346735,
                                                                                                         speed_accuracy: -1,
                                                                                                         latitude: 37.4929286 },
                                                                                                      timestamp: '2024-04-15T00:40:16.564Z' }
2024-04-14 20:40:46.584 22149-22149 TSLocationManager       com.jlink                      I  [c.t.t.TSFirebaseProxy$4 onSuccess] 
                                                                                                      ✅  Firestore INSERT: 241cfb06-6063-4d8c-ace1-04d30229105e -> 5sYPfDasQf3eRlEiz35O
christocracy commented 1 month ago
 ✅  Firestore INSERT: 241cfb06-6063-4d8c-ace1-04d30229105e -> 5sYPfDasQf3eRlEiz35O

Voila. It was sent to Firestore.

chris-eaheart commented 1 month ago

I see that - and I see the records going to firestore now. They weren't before. I'll have to dig into it more - it's behaving differently now, and the only code I changed was to add logging statements.

christocracy commented 1 month ago

Logs don’t affect performance, just like walking under ladders doesn’t bring bad luck. That’s superstition.