From 21ed9dbbd8c7be191894b11e895c1c0094b4aac6 Mon Sep 17 00:00:00 2001 From: amilasilva88 Date: Sat, 15 Aug 2015 09:29:14 +0800 Subject: Set Odometer only if there is a movement --- src/org/traccar/OdometerHandler.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/OdometerHandler.java b/src/org/traccar/OdometerHandler.java index 5a813fc3a..d5860c02e 100644 --- a/src/org/traccar/OdometerHandler.java +++ b/src/org/traccar/OdometerHandler.java @@ -31,11 +31,17 @@ public class OdometerHandler extends BaseDataHandler { private Position calculateDistance(Position position) { Position last = getLastPosition(position.getDeviceId()); if (last != null) { - double distance = DistanceCalculator.distance( - position.getLatitude(), position.getLongitude(), - last.getLatitude(), last.getLongitude()); - distance = Math.round((distance) * 100.0) / 100.0; - double odometer = distance + last.getOdometer(); + // set odometer only on movement + double odometer = 0.0; + if (last.getSpeed() == 0 && position.getSpeed() == 0) { + odometer = last.getOdometer(); + } else { + double distance = DistanceCalculator.distance( + position.getLatitude(), position.getLongitude(), + last.getLatitude(), last.getLongitude()); + distance = Math.round((distance) * 100.0) / 100.0; + odometer = distance + last.getOdometer(); + } position.setOdometer(odometer); } return position; -- cgit v1.2.3