1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-19 03:20:21 +02:00

Fix GPS getSpeed issue for devices that report hasSpeed as true, yet only return a 0 value for speed.

This commit is contained in:
illis 2023-08-30 21:31:21 +12:00
parent 600658d86b
commit fa5e91f966

View File

@ -36,6 +36,8 @@ public class GBLocationListener implements LocationListener {
private final EventHandler eventHandler;
private Location previousLocation;
// divide by 3.6 to get km/h to m/s
private static final double SPEED_THRESHOLD = 1.0 / 3.6;
public GBLocationListener(final EventHandler eventHandler) {
this.eventHandler = eventHandler;
@ -49,7 +51,9 @@ public class GBLocationListener implements LocationListener {
location.setTime(getLocationTimestamp(location));
// The location usually doesn't contain speed, compute it from the previous location
if (previousLocation != null && !location.hasSpeed()) {
// Some devices report hasSpeed() as true, and yet only return a 0 value, so we have to check against a speed threshold
boolean hasValidSpeed = location.hasSpeed() && (location.getSpeed() > SPEED_THRESHOLD);
if (previousLocation != null && !hasValidSpeed) {
long timeInterval = (location.getTime() - previousLocation.getTime()) / 1000L;
float distanceInMeters = previousLocation.distanceTo(location);
location.setSpeed(distanceInMeters / timeInterval);