aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/DistanceHandler.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-08-14 16:31:24 +0300
committerGitHub <noreply@github.com>2016-08-14 16:31:24 +0300
commit15b5ac0768ee7236d1af025460a3bdd4f8fa6994 (patch)
tree778506714b81ffb4fece27a4e6fa2eb5bf17e824 /src/org/traccar/DistanceHandler.java
parentd9777620508a7b197f0e5752869eef91d83e20a0 (diff)
parent6c8609aa3151246ab171995ef08c161e5d3b8242 (diff)
downloadtrackermap-server-15b5ac0768ee7236d1af025460a3bdd4f8fa6994.tar.gz
trackermap-server-15b5ac0768ee7236d1af025460a3bdd4f8fa6994.tar.bz2
trackermap-server-15b5ac0768ee7236d1af025460a3bdd4f8fa6994.zip
Merge pull request #2211 from Abyss777/distance
Changed way of summary distance calculation
Diffstat (limited to 'src/org/traccar/DistanceHandler.java')
-rw-r--r--src/org/traccar/DistanceHandler.java17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/org/traccar/DistanceHandler.java b/src/org/traccar/DistanceHandler.java
index 9f174a6c7..7537e2867 100644
--- a/src/org/traccar/DistanceHandler.java
+++ b/src/org/traccar/DistanceHandler.java
@@ -34,23 +34,30 @@ public class DistanceHandler extends BaseDataHandler {
public Position calculateDistance(Position position) {
double distance = 0.0;
+ double totalDistance = 0.0;
Position last = getLastPosition(position.getDeviceId());
if (last != null) {
- if (last.getAttributes().containsKey(Position.KEY_DISTANCE)) {
- distance = ((Number) last.getAttributes().get(Position.KEY_DISTANCE)).doubleValue();
+ if (last.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) {
+ totalDistance = ((Number) last.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue();
}
- if (position.getValid()) {
- distance += DistanceCalculator.distance(
+ if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
+ distance = DistanceCalculator.distance(
position.getLatitude(), position.getLongitude(),
last.getLatitude(), last.getLongitude());
distance = BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
+ } else {
+ distance = ((Number) position.getAttributes().get(Position.KEY_DISTANCE)).doubleValue();
}
}
+ if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
+ 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_DISTANCE, distance);
return position;
}