1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 11:26:47 +01:00

Give a more accurate representation of gps speed when manually calculating.

Dividing early makes us lose alot of precision.
This commit is contained in:
illis 2023-08-30 21:33:07 +12:00
parent fa5e91f966
commit 56fd2f8430

View File

@ -54,9 +54,9 @@ public class GBLocationListener implements LocationListener {
// 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());
float distanceInMeters = previousLocation.distanceTo(location);
location.setSpeed(distanceInMeters / timeInterval);
location.setSpeed(distanceInMeters / timeInterval * 1000L);
}
previousLocation = location;