locator: add a GPS lock to prevent location jumps
Hello!
This should fix #175 (closed) , specifically what I notice here: #175 (comment 1890849)
When Geoclue has a GPS lock, I have noticed that sometimes the location jumps back and forth, which is undesirable. What looks to be happening is this:
- The speed calculated here: https://gitlab.freedesktop.org/geoclue/geoclue/-/blob/master/src/gclue-locator.c#L112 uses whole seconds as a resolution, so 1 second can consider any location up to 500 m away valid, 2 seconds, 1 km, etc.
- MLS can give valid locations that are down to 10 m accuracy, so if they are within the 500 m accuracy and do not overlap with the GPS lock (which can happen since the GPS lock is so narrow), that location is chosen as a valid location. Then when the GPS gives an updated location, the GPS location is chosen again. This is the "jump". This has happened a few times if I an using the GPS for navigation and it thoroughly confuses Pure Maps.
In #175 (comment 1890849) , I proposed two possibilities: 1) only consider the GPS if there is a GPS lock, or 2) create a kalman filter to filter out bad locations. However, in working on the code, the kalman filter really only makes sense in the first place if there is a GPS lock in the first place, so I believe it adds unnecessary complexity into the code. Also, since the resolution in timestamps is whole seconds, it makes the kalman filter a lot more difficult to actually implement.
In the end, I introduced two variables that keep track of the GPS lock: GPS_lock
to know if there is a valid GPS lock, and GPS_lock_timestamp
to know the age of the last valid GPS_lock. As long as there is a valid GPS Lock, as determined by GPS_ACCURACY_THRESHOLD
, the timestamp updates. I use the same threshold as the MOZILLA_SUBMISSION_THRESHOLD
to determine if a GPS Lock is valid. I also have a MAX_GPS_AGE
in case GPS temporarily loses lock (e.g. if you are driving and go into a tunnel, or walk in and out of a building) and comes back to now have the location jump. I felt 60 seconds was a decent threshold for GPS, but I am open to it being changed.
I also have the g_debug ()
s to help with testing, but they could probably be dropped (or at least some of them). There is also a trailing whitespace my editor likes to delete, so I just put that in a separate commit. That can be dropped if desired.