aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/helper')
-rw-r--r--src/main/java/org/traccar/helper/model/PositionUtil.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/helper/model/PositionUtil.java b/src/main/java/org/traccar/helper/model/PositionUtil.java
index 64216a937..644517dac 100644
--- a/src/main/java/org/traccar/helper/model/PositionUtil.java
+++ b/src/main/java/org/traccar/helper/model/PositionUtil.java
@@ -28,4 +28,17 @@ public final class PositionUtil {
return lastPosition == null || position.getFixTime().compareTo(lastPosition.getFixTime()) >= 0;
}
+ public static double calculateDistance(Position first, Position last, boolean useOdometer) {
+ double distance;
+ double firstOdometer = first.getDouble(Position.KEY_ODOMETER);
+ double lastOdometer = last.getDouble(Position.KEY_ODOMETER);
+
+ if (useOdometer && firstOdometer != 0.0 && lastOdometer != 0.0) {
+ distance = lastOdometer - firstOdometer;
+ } else {
+ distance = last.getDouble(Position.KEY_TOTAL_DISTANCE) - first.getDouble(Position.KEY_TOTAL_DISTANCE);
+ }
+ return distance;
+ }
+
}