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

Getting Incorrect Locations #2193

Open shubhlumber opened 3 weeks ago

shubhlumber commented 3 weeks ago

Your Environment

Expected Behavior

Getting Correct Locations Point

Actual Behavior

At 2024-10-18 06:56:26.885, the library generated this location: πŸ“<+40.94316423, -111.89047783> +/- 68.46m (speed -1.00 m/s, course -1.00) @ 10/18/24, 6:51:36 AM MDT

Then, at 2024-10-18 06:56:40.789, the library generated this location: πŸ“<+40.98457200, -111.89573687> +/- 4.58m (speed 0.00 m/s, course -1.00) @ 10/18/24, 6:56:40 AM MDT

These two points are about 3.3 miles apart, which seems impossible within this short time frame. Could you help us understand why such a large location shift is occurring?

Steps to Reproduce

1. 2. 3. 4.

Context

Debug logs

Logs ``` 2024-10-18 06:56:23.269 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager stop] β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:23.269 ℹ️-[TSLocationManager clearLastOdometerLocation] 2024-10-18 06:56:23.269 πŸ”΄-[TSGeofenceManager stop] 2024-10-18 06:56:23.269 πŸ”΄-[TSGeofenceManager stopMonitoringSignificantLocationChanges] 2024-10-18 06:56:23.269 πŸ”΄-[TSGeofenceManager stopUpdatingLocation] 2024-10-18 06:56:23.269 πŸ”΄-[TSGeofenceManager stopMonitoringGeofences] 2024-10-18 06:56:23.271 πŸ”΄-[PolygonGeofencingService stop] 2024-10-18 06:56:23.272 ℹ️-[PolygonGeofencingService persistMonitoredPolygons] { } 2024-10-18 06:56:23.272 πŸ”΄-[TSLocationManager stopUpdatingLocation] 2024-10-18 06:56:23.273 ℹ️-[TSDBLogger db_save] Log committed 2024-10-18 06:56:23.298 πŸ”΄-[TSLocationManager stopMonitoringBackgroundFetch] BackgroundFetch: OFF 2024-10-18 06:56:23.298 πŸ”΄-[TSLocationManager stopMonitoringSignificantLocationChanges] 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager log:message:] [RNBackgroundGeolocation startObserving] 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] location 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] motionchange 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] activitychange 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] heartbeat 2024-10-18 06:56:23.298 ℹ️-[TSGeofenceManager onGeofence:] 2024-10-18 06:56:23.298 ℹ️-[TSGeofenceManager onGeofencesChange:] 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] http 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] providerchange 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] schedule 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] powersavechange 2024-10-18 06:56:23.298 ℹ️-[TSHttpService onConnectivityChange:] 2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] enabledchange 2024-10-18 06:56:23.298 ℹ️-[TSHttpService onAuthorization:] 2024-10-18 06:56:23.305 ℹ️-[TSConfig persist] 2024-10-18 06:56:23.307 ℹ️-[TSConfig persist] 2024-10-18 06:56:23.308 ℹ️-[TSConfig persist] 2024-10-18 06:56:23.308 ℹ️-[TSConfig persist] 2024-10-18 06:56:23.309 βœ…-[LocationDAO unlock]_block_invoke UNLOCKED ALL RECORDS 2024-10-18 06:56:23.309 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 1 2024-10-18 06:56:23.309 ℹ️-[TSConfig persist] 2024-10-18 06:56:23.309 ℹ️-[TSConfig persist] 2024-10-18 06:56:23.310 πŸ”΅-[TSLocationManager ready] 2024-10-18 06:56:23.933 ℹ️-[TSLog destroy] SUCCESS 2024-10-18 06:56:26.864 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager start] β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:26.864 ℹ️-[TSLocationManager doStart:] trackingMode: 1 2024-10-18 06:56:26.864 ℹ️-[TSConfig persist] 2024-10-18 06:56:26.866 🎾-[TSGeofenceManager start] 2024-10-18 06:56:26.867 🎾-[SOMotionDetector startDetection] 2024-10-18 06:56:26.867 πŸ”΅-[TSLocationManager setPace:] 0 2024-10-18 06:56:26.871 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON 2024-10-18 06:56:26.883 βœ…-[SOMotionDetector startDetection]_block_invoke Enabled M7 MotionActivity updates 2024-10-18 06:56:26.883 ℹ️+[LocationAuthorization run:onCancel:] status: 3 2024-10-18 06:56:26.884 🎾-[TSLocationManager startMonitoringBackgroundFetch] BackgroundFetch: ON 2024-10-18 06:56:26.885 πŸ“<+40.94316423,-111.89047783> +/- 68.46m (speed -1.00 mps / course -1.00) @ 10/18/24, 6:51:36β€―AM Mountain Daylight Time 2024-10-18 06:56:26.885 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | df: -1.0m | age: 290403 ms β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:26.885 ℹ️-[TSLocationManager locationManager:didUpdateLocations:] Received stale motionchange location. Retrying... 2024-10-18 06:56:26.890 ℹ️-[TSLocationManager startMonitoringBackgroundFetch]_block_invoke Configured BackgroundFetch 2024-10-18 06:56:26.905 πŸ“<+40.98391033,-111.89461335> +/- 228.33m (speed -1.00 mps / course -1.00) @ 10/18/24, 6:56:26β€―AM Mountain Daylight Time 2024-10-18 06:56:26.905 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | df: -1.0m | age: 8 ms β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:26.905 βœ…-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+40.94316423,-111.89047783> +/- 68.46m (speed -1.00 mps / course -1.00) @ 10/18/24, 6:51:36β€―AM Mountain Daylight Time 2024-10-18 06:56:26.905 πŸ”΅-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 200 2024-10-18 06:56:26.906 πŸ”΄-[TSLocationManager stopUpdatingLocation] 2024-10-18 06:56:26.906 πŸ”΅-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 68.5 2024-10-18 06:56:26.906 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-18 06:56:26.906 🎾-[TSLocationManager startMonitoringSignificantLocationChanges] 2024-10-18 06:56:26.908 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 1 2024-10-18 06:56:26.908 βœ…-[TSLocationManager persistLocation:]_block_invoke INSERT: 43AA54CA-28C1-48C6-B764-1FDD8E8F8927 2024-10-18 06:56:26.925 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-18 06:56:33.181 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0 β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:34.746 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0 β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:37.618 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0 β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:40.177 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0 β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:40.776 ⚠️-[TSLocationManager start] Already started (ignored) 2024-10-18 06:56:40.777 πŸ”΅-[TSLocationManager getCurrentPosition:] 2024-10-18 06:56:40.777 🎾-[LocationManager startUpdatingLocation] ON 2024-10-18 06:56:40.779 ℹ️-[TSConfig persist] 2024-10-18 06:56:40.783 ℹ️-[TSConfig persist] 2024-10-18 06:56:40.784 ℹ️-[TSDBLogger db_save] Log committed 2024-10-18 06:56:40.785 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 1 2024-10-18 06:56:40.785 ℹ️-[TSConfig persist] 2024-10-18 06:56:40.789 ℹ️+[LocationAuthorization run:onCancel:] status: 3 2024-10-18 06:56:40.789 πŸ“<+40.98457200,-111.89573687> +/- 4.58m (speed 0.00 mps / course -1.00) @ 10/18/24, 6:56:40β€―AM Mountain Daylight Time 2024-10-18 06:56:40.789 πŸ”΄-[LocationManager stopUpdatingLocation] OFF 2024-10-18 06:56:40.789 ╔═══════════════════════════════════════════════════════════ β•‘ -[LocationManager locationManager:didUpdateLocations:] Sample 1 of 1 (589 ms old) β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:40.789 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-18 06:56:40.789 πŸ”΅-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 36.5 2024-10-18 06:56:40.789 ℹ️-[TSConfig persist] 2024-10-18 06:56:40.790 πŸ”΅-[TSConfig incrementOdometer:] 76497.0 2024-10-18 06:56:40.790 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-18 06:56:40.797 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 1 2024-10-18 06:56:40.797 βœ…-[TSLocationManager persistLocation:]_block_invoke INSERT: 38C108E8-5BC5-4907-86B1-2F9D3DDD35B9 2024-10-18 06:56:40.814 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSHttpService flush:] β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:40.815 βœ…-[BackgroundTaskManager createBackgroundTask] 11 2024-10-18 06:56:40.816 βœ…-[TSHttpService schedulePost] LOCKED: 38C108E8-5BC5-4907-86B1-2F9D3DDD35B9 2024-10-18 06:56:41.253 ℹ️-[TSLog destroy] SUCCESS 2024-10-18 06:56:41.965 πŸ”΅-[HttpResponse handleResponse] Response: 200 2024-10-18 06:56:41.972 βœ…-[TSHttpService post:]_block_invoke DESTROY: 38C108E8-5BC5-4907-86B1-2F9D3DDD35B9 2024-10-18 06:56:41.972 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSHttpService finish:error:] Success: 1 β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 2024-10-18 06:56:41.972 βœ…-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 11 OF ( 11 ) 2024-10-18 06:56:43.087 πŸ”΅-[TSLocationManager onSuspend:] enabled? 1) 2024-10-18 06:56:43.092 ℹ️-[TSDBLogger db_save] Log committed 2024-10-18 06:56:43.110 ℹ️-[TSDBLogger db_save] Log committed 2024-10-18 06:56:43.110 ℹ️-[TSLocationManager removeListeners] 2024-10-18 06:56:43.110 πŸ”΅-[TSLocationManager onAppTerminate] stopOnTerminate? 0 2024-10-18 06:56:43.110 πŸ”΅-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 200 2024-10-18 07:01:21.475 ℹ️-[TSDBLogger db_delete] maxAge: 259200 2024-10-18 07:01:21.477 ℹ️-[TSLocationManager init] 2024-10-18 07:01:21.478 ℹ️-[GeofenceDAO init] CREATE TABLE IF NOT EXISTS geofences (id INTEGER PRIMARY KEY AUTOINCREMENT, identifier TEXT NOT NULL UNIQUE, latitude DOUBLE NOT NULL, sin_latitude DOUBLE NOT NULL, cos_latitude DOUBLE NOT NULL, longitude DOUBLE NOT NULL, sin_longitude DOUBLE NOT NULL, cos_longitude DOUBLE NOT NULL, radius DOUBLE NOT NULL, notifyOnEntry BOOLEAN NOT NULL DEFAULT 0, notifyOnExit BOOLEAN NOT NULL DEFAULT 0, notifyOnDwell BOOLEAN NOT NULL DEFAULT 0, loiteringDelay DOUBLE NOT NULL DEFAULT 0, extras TEXT, vertices TEXT) 2024-10-18 07:01:21.478 ℹ️-[GeofenceDAO init] CREATE index IF NOT EXISTS identifier ON geofences (identifier);CREATE index IF NOT EXISTS latitude ON geofences (latitude);CREATE index IF NOT EXISTS longitude ON geofences (longitude);CREATE index IF NOT EXISTS sin_latitude ON geofences (sin_latitude);CREATE index IF NOT EXISTS cos_latitude ON geofences (cos_latitude);CREATE index IF NOT EXISTS sin_longitude ON geofences (sin_longitude);CREATE index IF NOT EXISTS cos_longitude ON geofences (cos_longitude); 2024-10-18 07:01:21.499 πŸ”΅-[TSLocationManager locationManager:didChangeAuthorizationStatus:] status 3 2024-10-18 07:01:21.503 πŸ”΅-[LocationManager locationManager:didChangeAuthorizationStatus:] 3 2024-10-18 07:01:21.503 πŸ”΅-[PolygonGeofencingService locationManager:didChangeAuthorizationStatus:] 3 2024-10-18 07:01:21.503 πŸ”΅-[BackgroundTaskManager locationManager:didChangeAuthorizationStatus:] 3 2024-10-18 07:01:21.503 πŸ”΅-[LocationManager locationManager:didChangeAuthorizationStatus:] 3 2024-10-18 07:01:21.503 πŸ”΅-[LocationManager locationManager:didChangeAuthorizationStatus:] 3 2024-10-18 07:01:21.503 ℹ️+[LocationAuthorization run:onCancel:] status: 3 2024-10-18 07:01:21.598 ╔═══════════════════════════════════════════════════════════ β•‘ -[TSLocationManager stop] β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• ```
christocracy commented 3 weeks ago

The plug-in is only the mailman, delivering to you locations provided by the native location api.

One location has an accuracy of 68.46m (probably provided by wifi) while the other was 4.58m (probably from gps).

If you don’t like the location.coords.accuracy of some particular location, throw it away.

shubhlumber commented 3 weeks ago

Since we are using the library's URL method, which automatically sends the coordinates to our API database, how can we filter out locations based on location.coords.accuracy for specific coordinates?

christocracy commented 3 weeks ago

how can we filter out locations based on location.coords.accuracy for specific coordinates?

At your server, you should analyze incoming data and throw out undesirable locations.

shubhlumber commented 3 weeks ago

Currently, we are sending the following locationTemplate to our database:

{"latitude":<%= latitude %>,"longitude":<%= longitude %>,"time":"<%= timestamp %>"}

This includes only latitude, longitude, and time. Is there a way to also fetch location.coords.accuracy so that we can save it in our database and use it for filtering?

christocracy commented 3 weeks ago

See the API docs Config.locationTemplate to learn about how which attributes are available to you in your template.