mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 13:26:50 +01: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:
parent
600658d86b
commit
fa5e91f966
@ -36,6 +36,8 @@ public class GBLocationListener implements LocationListener {
|
|||||||
private final EventHandler eventHandler;
|
private final EventHandler eventHandler;
|
||||||
|
|
||||||
private Location previousLocation;
|
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) {
|
public GBLocationListener(final EventHandler eventHandler) {
|
||||||
this.eventHandler = eventHandler;
|
this.eventHandler = eventHandler;
|
||||||
@ -49,7 +51,9 @@ public class GBLocationListener implements LocationListener {
|
|||||||
location.setTime(getLocationTimestamp(location));
|
location.setTime(getLocationTimestamp(location));
|
||||||
|
|
||||||
// The location usually doesn't contain speed, compute it from the previous 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;
|
long timeInterval = (location.getTime() - previousLocation.getTime()) / 1000L;
|
||||||
float distanceInMeters = previousLocation.distanceTo(location);
|
float distanceInMeters = previousLocation.distanceTo(location);
|
||||||
location.setSpeed(distanceInMeters / timeInterval);
|
location.setSpeed(distanceInMeters / timeInterval);
|
||||||
|
Loading…
Reference in New Issue
Block a user