diff options
Diffstat (limited to 'src/org/traccar/OdometerHandler.java')
-rw-r--r-- | src/org/traccar/OdometerHandler.java | 16 |
1 files changed, 11 insertions, 5 deletions
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; |