aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-11-14 07:35:45 -0800
committerAnton Tananaev <anton@traccar.org>2023-11-14 07:35:45 -0800
commit3aa0729fba832e13da2fd0a6a1c600636fa235a9 (patch)
treed4fcdfa5fecfed8168c4399329246d03dab18a03 /src/main/java/org/traccar/handler
parentcd5413ae082a55e94d46f38a2a73f72eddb92aca (diff)
downloadtrackermap-server-3aa0729fba832e13da2fd0a6a1c600636fa235a9.tar.gz
trackermap-server-3aa0729fba832e13da2fd0a6a1c600636fa235a9.tar.bz2
trackermap-server-3aa0729fba832e13da2fd0a6a1c600636fa235a9.zip
Prefer used fuel attribute
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/DistanceHandler.java16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/handler/DistanceHandler.java b/src/main/java/org/traccar/handler/DistanceHandler.java
index 6bb774a15..db8c73779 100644
--- a/src/main/java/org/traccar/handler/DistanceHandler.java
+++ b/src/main/java/org/traccar/handler/DistanceHandler.java
@@ -17,6 +17,8 @@
package org.traccar.handler;
import io.netty.channel.ChannelHandler;
+import jakarta.inject.Inject;
+import jakarta.inject.Singleton;
import org.traccar.BaseDataHandler;
import org.traccar.config.Config;
import org.traccar.config.Keys;
@@ -24,11 +26,6 @@ import org.traccar.helper.DistanceCalculator;
import org.traccar.model.Position;
import org.traccar.session.cache.CacheManager;
-import jakarta.inject.Inject;
-import jakarta.inject.Singleton;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-
@Singleton
@ChannelHandler.Sharable
public class DistanceHandler extends BaseDataHandler {
@@ -54,8 +51,7 @@ public class DistanceHandler extends BaseDataHandler {
if (position.hasAttribute(Position.KEY_DISTANCE)) {
distance = position.getDouble(Position.KEY_DISTANCE);
}
- double totalDistance = 0.0;
-
+ double totalDistance;
Position last = cacheManager.getPosition(position.getDeviceId());
if (last != null) {
totalDistance = last.getDouble(Position.KEY_TOTAL_DISTANCE);
@@ -63,7 +59,6 @@ public class DistanceHandler extends BaseDataHandler {
distance = DistanceCalculator.distance(
position.getLatitude(), position.getLongitude(),
last.getLatitude(), last.getLongitude());
- distance = BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
}
if (filter && last.getLatitude() != 0 && last.getLongitude() != 0) {
boolean satisfiesMin = minError == 0 || distance > minError;
@@ -75,10 +70,11 @@ public class DistanceHandler extends BaseDataHandler {
distance = 0;
}
}
+ } else {
+ totalDistance = 0.0;
}
position.set(Position.KEY_DISTANCE, distance);
- totalDistance = BigDecimal.valueOf(totalDistance + distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
- position.set(Position.KEY_TOTAL_DISTANCE, totalDistance);
+ position.set(Position.KEY_TOTAL_DISTANCE, totalDistance + distance);
return position;
}