diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-08-25 03:17:41 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-25 03:17:41 +1200 |
commit | 516d1f157a762c3bd54e0ffc2f3c71547d49773c (patch) | |
tree | 0491a9542e632741ce070aae1aa87a4decfeda88 /src/org/traccar/reports/ReportUtils.java | |
parent | ea0bdea88003f46fd6f6164d5c45e33d53f47c81 (diff) | |
parent | 5e8dbc78110ab5e28d1d57277a38dd1991dba0e6 (diff) | |
download | trackermap-server-516d1f157a762c3bd54e0ffc2f3c71547d49773c.tar.gz trackermap-server-516d1f157a762c3bd54e0ffc2f3c71547d49773c.tar.bz2 trackermap-server-516d1f157a762c3bd54e0ffc2f3c71547d49773c.zip |
Merge pull request #2247 from Abyss777/odometer
Fixed optional odometer for wondex protocol and exclusion for 0.0 odometers
Diffstat (limited to 'src/org/traccar/reports/ReportUtils.java')
-rw-r--r-- | src/org/traccar/reports/ReportUtils.java | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index 67d577904..924dff4c1 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -45,10 +45,16 @@ public final class ReportUtils { public static double calculateDistance(Position firstPosition, Position lastPosition, boolean useOdometer) { double distance = 0.0; - if (useOdometer && firstPosition.getAttributes().containsKey(Position.KEY_ODOMETER) - && lastPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) { - distance = (((Number) lastPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue() - - ((Number) firstPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue()); + double firstOdometer = 0.0; + double lastOdometer = 0.0; + if (firstPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) { + firstOdometer = ((Number) firstPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue(); + } + if (lastPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) { + lastOdometer = ((Number) lastPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue(); + } + if (useOdometer && (firstOdometer != 0.0 || lastOdometer != 0.0)) { + distance = lastOdometer - firstOdometer; } else if (firstPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE) && lastPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) { distance = ((Number) lastPosition.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue() |