aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/ODOMeterHandler.java
diff options
context:
space:
mode:
authoramilasilva88 <amilasilva88@gmail.com>2015-08-13 20:28:58 +0800
committeramilasilva88 <amilasilva88@gmail.com>2015-08-13 20:28:58 +0800
commit0350d762a7c08199e79dc401b6c6821d7e2a21bd (patch)
tree5b0751fb43278026aee2c153ae131e17776beecd /src/org/traccar/ODOMeterHandler.java
parenta5b29b0e5df4ba84c8eaa8944258b9c9e12472db (diff)
downloadtrackermap-server-0350d762a7c08199e79dc401b6c6821d7e2a21bd.tar.gz
trackermap-server-0350d762a7c08199e79dc401b6c6821d7e2a21bd.tar.bz2
trackermap-server-0350d762a7c08199e79dc401b6c6821d7e2a21bd.zip
Added ODOMeter and Modification to Mobile UI
Diffstat (limited to 'src/org/traccar/ODOMeterHandler.java')
-rw-r--r--src/org/traccar/ODOMeterHandler.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/org/traccar/ODOMeterHandler.java b/src/org/traccar/ODOMeterHandler.java
new file mode 100644
index 000000000..1dc3aed44
--- /dev/null
+++ b/src/org/traccar/ODOMeterHandler.java
@@ -0,0 +1,51 @@
+/**
+ *
+ */
+package org.traccar;
+
+import org.traccar.helper.DistanceCalculator;
+import org.traccar.helper.Log;
+import org.traccar.model.Position;
+
+/**
+ * <p>
+ * ODO Meter handler
+ * </p>
+ *
+ * @author Amila Silva
+ *
+ */
+public class ODOMeterHandler extends BaseDataHandler {
+
+ public ODOMeterHandler() {
+ Log.debug("System based ODO meter calculation enabled for all devices");
+ }
+
+ private Position getLastPosition(long deviceId) {
+ if (Context.getConnectionManager() != null) {
+ return Context.getConnectionManager().getLastPosition(deviceId);
+ }
+ return null;
+ }
+
+ 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();
+ Log.info("::: Device Course : " + position.getDeviceId()
+ + ", Distance :" + distance + "m, ODO Meter :" + odoMeter + " m");
+ position.setOdoMeter(odoMeter);
+ }
+ return position;
+ }
+
+ @Override
+ protected Position handlePosition(Position position) {
+ return calculateDistance(position);
+ }
+
+}