aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/helper
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-10 07:56:49 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-10 07:56:49 -0700
commitbbe84d6a751fdc840e4201ef9027a96527006049 (patch)
tree4165d09a134eb1c1c61438b17fe44f5a1fcd0654 /src/main/java/org/traccar/helper
parentc03b4a2ace925e6a0d7c43ce59e14ddb9cbf18a9 (diff)
downloadtrackermap-server-bbe84d6a751fdc840e4201ef9027a96527006049.tar.gz
trackermap-server-bbe84d6a751fdc840e4201ef9027a96527006049.tar.bz2
trackermap-server-bbe84d6a751fdc840e4201ef9027a96527006049.zip
Inject report utils
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;
+ }
+
}