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

speedJumpFilter feature requested on iOS #2192

Open mbuttin opened 3 weeks ago

mbuttin commented 3 weeks ago

I use the speedJumpFilter:100 setting in my BackgroundGeolocation.ready parameters, to avoid unexpected jumps of location. It looks to works really well on my android devices, as I didn't detect major jumps.

On the iphone I'm using to test, there are quite a lot of jumps, as the speedJumpFilter is for Android only.

So, is it possible to build a similar function for iphone ? And if it's not "built in" in the os, is it possible to create it in the plugin ?

Your Environment

Expected Behavior

No jumps on iOS, like in Android

Actual Behavior

There are jumps on iOS

Steps to Reproduce

  1. walk with 2 devices : 1 android and 1 iphone, tracking the position
  2. see that android position follow the path and iphone occurs to jump

Context

Track without jumps

Debug logs

Logs ``` ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:52:53.227 🔵-[TSLocationManager detectStopMotion:shakeCount:] Stationary-time: 137/600 s 2024-10-28 11:52:53.873 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:52:53.875 🔵-[TSLocationManager detectStopMotion:shakeCount:] Stationary-time: 138/600 s 2024-10-28 11:52:55.485 ℹ️-[TSDBLogger db_save] Log committed 2024-10-28 11:53:02.612 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/66 | isMoving: 1 ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:53:02.616 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON 2024-10-28 11:53:02.619 ℹ️-[TSLocationManager resetStopTimeoutTimer] 2024-10-28 11:53:02.751 ℹ️+[LocationAuthorization run:onCancel:] status: 3 2024-10-28 11:53:02.752 📍<+45.89013273,+4.96862896> +/- 35.00m (speed -1.00 mps / course -1.00) @ 28/10/2024 11:51:15 Central European Standard Time 2024-10-28 11:53:02.752 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 106901 ms ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:53:02.752 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 24.0 2024-10-28 11:53:02.752 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-28 11:53:02.753 📍<+45.89432189,+4.97876263> +/- 19138.00m (speed -1.00 mps / course -1.00) @ 28/10/2024 11:53:02 Central European Standard Time 2024-10-28 11:53:02.753 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 106 ms ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:53:02.753 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 32.0 2024-10-28 11:53:02.753 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-28 11:53:03.063 📍<+45.89462113,+4.97948650> +/- 19138.00m (speed -1.00 mps / course -1.00) @ 28/10/2024 11:53:03 Central European Standard Time 2024-10-28 11:53:03.063 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 3 ms ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:53:03.063 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 32.0 2024-10-28 11:53:03.063 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-28 11:53:05.523 📍<+45.89003901,+4.96888058> +/- 48.00m (speed 2.06 mps / course -1.00) @ 28/10/2024 11:53:05 Central European Standard Time 2024-10-28 11:53:05.523 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 135 ms ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:53:05.524 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 32.0 2024-10-28 11:53:05.524 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-28 11:53:06.492 📍<+45.89008789,+4.96887347> +/- 32.00m (speed 2.06 mps / course -1.00) @ 28/10/2024 11:53:06 Central European Standard Time 2024-10-28 11:53:06.492 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 101 ms ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:53:06.492 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 32.0 2024-10-28 11:53:06.492 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-28 11:53:08.540 📍<+45.89005112,+4.96882703> +/- 16.00m (speed 1.86 mps / course -1.00) @ 28/10/2024 11:53:08 Central European Standard Time 2024-10-28 11:53:08.540 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 149 ms ╚═══════════════════════════════════════════════════════════ 2024-10-28 11:53:08.541 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 32.0 2024-10-28 11:53:08.541 ℹ️-[PolygonGeofencingService setLocation:] Already updating location 2024-10-28 11:53:10.373 ```
christocracy commented 3 weeks ago

Looking at your logged locations, do you see why you’re experiencing “jumps”?

mbuttin commented 3 weeks ago

No, I'm not sure to understand.

Those lines : 2024-10-28 11:53:05.524 ℹ️-[PolygonGeofencingService setLocation:] Already updating location

make me think that this update should be ignored, but it fire my onLocation event.

Want to point out that the jumps didn't follow the path, they're erratic.

Could you please give me some guidelines if you see something that is not done well, or that I could improve ?

Thanks

christocracy commented 3 weeks ago

Do you see the problem with this location that was provided by the native location API?

2024-10-28 11:53:02.753 📍<+45.89432189,+4.97876263> +/- 19138.00m (speed -1.00 mps / course -1.00) @ 28/10/2024 11:53:02 Central European Standard Time

mbuttin commented 3 weeks ago

I can see that it's far away from the previous one ? Don't know what exactly the 19138m is supposed to be, because this location is about 500m far from my real location. What else I'm missing ? And what do you mean "by the native location API?" It's not provided by the plugin ?

christocracy commented 3 weeks ago

Don't know what exactly the 19138m is supposed to be

That is the location.coords.accuracy of that location. It’s nearly 20km.

You should filter that location out.

A location is not a dimensionless point in space — it is a circle of radius accuracy. The device’s true location is somewhere inside that circle. The typical accuracy of a location provided by GPS is ~5 meters.

A location with accuracy ~20000 meters did not come from GPS, it came from a cell tower.

mbuttin commented 3 weeks ago

Ok, I understand better. And is there an easy way to do that within the plugin ? Like a "minimum accuracy" above which onLocation will not fire ? Or what's the best way to filter this when the onLocation event fire ?

christocracy commented 3 weeks ago

And is there an easy way to do that within the plugin

No. Just analyze location.coords.accuracy and filter as-desired.

mbuttin commented 3 weeks ago

Ok, will do that, thanks for your help. Feel like it could be a parameter in the plugin, as it's better if the plugin is able to filter locations as we want and output only the desired locations. And it could probably be the same parameter speedjumpfilter like android...

christocracy commented 3 weeks ago

It’s highly unusual to see a location with 20000 meters accuracy. I only see that when taking off in an airplane.

mbuttin commented 3 weeks ago

I was just walking for 1hr and continue for 3hrs. I'll check how many peaks I got, and the accuracy of small jumps (I already spot a small jump (less than 50m) and the accuracy was 68m. From what I see, the usual accuracy of normal points is around 35m (but it's really better in reality, probably accurate like 5-10 meters).

mbuttin commented 3 weeks ago

For example, this is a "small jump" : 1st and 4th position are pretty accurate concerning reality, but position 2 and 3 have "jump" few meters. Accuracy is pretty consistent around +-35m. I beg that a speed simulation could show that those points are "too fast".

2024-10-28 11:50:21.215 📍<+45.89017442,+4.96871888> +/- 35.00m (speed -1.00 mps / course -1.00) @ 28/10/2024 11:50:21 Central European Standard Time

2024-10-28 11:50:21.215 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 10 ms ╚═══════════════════════════════════════════════════════════

2024-10-28 11:50:21.215 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 24.0

2024-10-28 11:50:21.215 ℹ️-[PolygonGeofencingService setLocation:] Already updating location

2024-10-28 11:50:24.605 📍<+45.89036411,+4.96849396> +/- 32.00m (speed 0.26 mps / course -1.00) @ 28/10/2024 11:50:24 Central European Standard Time

2024-10-28 11:50:24.605 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 152 ms ╚═══════════════════════════════════════════════════════════

2024-10-28 11:50:24.606 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 24.0

2024-10-28 11:50:24.606 ℹ️-[PolygonGeofencingService setLocation:] Already updating location

2024-10-28 11:50:25.588 📍<+45.89024222,+4.96855212> +/- 32.00m (speed 0.21 mps / course -1.00) @ 28/10/2024 11:50:25 Central European Standard Time

2024-10-28 11:50:25.588 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 107 ms ╚═══════════════════════════════════════════════════════════

2024-10-28 11:50:25.588 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 24.0

2024-10-28 11:50:25.588 ℹ️-[PolygonGeofencingService setLocation:] Already updating location

2024-10-28 11:50:25.653 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0 ╚═══════════════════════════════════════════════════════════

2024-10-28 11:50:25.653 🔵-[TSLocationManager startMotionTriggerTimer] Motion-trigger timer engaged: Stop-detection will trigger in 10 seconds...

2024-10-28 11:50:26.597 📍<+45.89014730,+4.96863744> +/- 32.00m (speed 0.26 mps / course -1.00) @ 28/10/2024 11:50:26 Central European Standard Time

mbuttin commented 3 weeks ago

This one is a bit more important : position 1 and 3 are fine, position 2 is jumped. Accruacy is worst on position 2, but still not bad +-64m...

2024-10-28 12:07:53.025 📍<+45.89302803,+4.96913074> +/- 35.00m (speed -1.00 mps / course -1.00) @ 28/10/2024 12:07:53 Central European Standard Time

2024-10-28 12:07:53.025 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 24 ms ╚═══════════════════════════════════════════════════════════

2024-10-28 12:07:53.025 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 6.0

2024-10-28 12:07:53.025 ℹ️-[PolygonGeofencingService setLocation:] Already updating location

2024-10-28 12:07:55.706 📍<+45.89335620,+4.96901824> +/- 64.00m (speed 1.05 mps / course -1.00) @ 28/10/2024 12:07:55 Central European Standard Time

2024-10-28 12:07:55.706 ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 10.0m | age: 113 ms ╚═══════════════════════════════════════════════════════════

2024-10-28 12:07:55.707 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 6.0

2024-10-28 12:07:55.707 ℹ️-[TSConfig persist]

2024-10-28 12:07:55.714 🔵-[TSConfig incrementOdometer:] 51812.1

2024-10-28 12:07:55.715 ℹ️-[PolygonGeofencingService setLocation:] Already updating location

2024-10-28 12:07:56.714 📍<+45.89312704,+4.96916143> +/- 16.00m (speed 1.05 mps / course -1.00) @ 28/10/2024 12:07:56 Central European Standard Time

christocracy commented 3 weeks ago

What do those locations look like plotted on a map?

32 meters is not that bad of an accuracy.

mbuttin commented 3 weeks ago

What do those locations look like plotted on a map?

The ones that I says "goods" are really "on my real path" on my map, and really follows the android ones. The ones that are "jumped" are scattered (more or less far) and are not similar to android ones.

The android ones really stays "on my real path", probably thanks to speedjumpfilter.

I should say that the accuracy value is probably theoric, because in most of cases, the location looks good at less than 5-10m (instead of the +-35m). That's why we really notice those iOS jumps, that looks innacurate comparatively to android. I still have to test on another iphone to check if it appears on all models.

If the accuracy filter eliminate the most big jumps, it could be fine enough, I'll test that tomorrow. But at the end of the day, it could be better to have the accuracy I have on my android devices also on the iphone.

christocracy commented 3 weeks ago

these locations you report are not within the realm of speedJumpFilter. speedJumpFilter is designed to filter out grossly incorrect "jumps", where the only way to get from point A -> B in the given time would be in a Jet airplane.

A jump of 40 meters in ~ 3 seconds would not be captured by speedJumpFilter.

christocracy commented 3 weeks ago

I suggest you see API docs Config.transistorAuthorizationToken to easily configure your to post data to my demo server at https://tracker.transistorsoft.com so I can observe your data on a map. Let me know the orgname you choose.

mbuttin commented 3 weeks ago

You're right. So maybe the android phones gps is just more "stable" than the iphone one ? (2 samsung and 1 redmi vs an iphone 7)

Ok, I'll look to upload locations on the demo server, thx.

christocracy commented 3 weeks ago

So maybe the android phones gps is just more "stable" than the iphone one

Not from my more than 10 years experience. iOS is the more reliable one.

christocracy commented 3 weeks ago

This is what a typical walk with iOS looks like:

iPhone 15 Pro @ iOS 18.1

Screenshot 2024-10-28 at 3 45 28 PM

Google Pixel 6 @ Android 15.

Screenshot 2024-10-28 at 3 46 16 PM