aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/CoordinatesHandler.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-08-08 10:31:49 +0300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-08-08 10:31:49 +0300
commitecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0 (patch)
tree9e4e98e2d35c36b2fcab3026169141fdc6ee2ba1 /src/org/traccar/CoordinatesHandler.java
parent5c0e9d5eff4f471837ad26aa763ac8b5dc7fc501 (diff)
downloadtrackermap-server-ecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0.tar.gz
trackermap-server-ecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0.tar.bz2
trackermap-server-ecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0.zip
Add coordinates filter (fix #2192)
Diffstat (limited to 'src/org/traccar/CoordinatesHandler.java')
-rw-r--r--src/org/traccar/CoordinatesHandler.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/org/traccar/CoordinatesHandler.java b/src/org/traccar/CoordinatesHandler.java
new file mode 100644
index 000000000..2dcb3c632
--- /dev/null
+++ b/src/org/traccar/CoordinatesHandler.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar;
+
+import org.traccar.helper.DistanceCalculator;
+import org.traccar.model.Position;
+
+public class CoordinatesHandler extends BaseDataHandler {
+
+ private final int coordinatesError;
+
+ public CoordinatesHandler() {
+ Config config = Context.getConfig();
+ coordinatesError = config.getInteger("coordinates.error", 50);
+ }
+
+ private Position getLastPosition(long deviceId) {
+ if (Context.getIdentityManager() != null) {
+ return Context.getIdentityManager().getLastPosition(deviceId);
+ }
+ return null;
+ }
+
+ @Override
+ protected Position handlePosition(Position position) {
+ Position last = getLastPosition(position.getDeviceId());
+ if (last != null) {
+ double distance = DistanceCalculator.distance(
+ position.getLatitude(), position.getLongitude(), last.getLatitude(), last.getLongitude());
+ if (distance < coordinatesError) {
+ position.setLatitude(last.getLatitude());
+ position.setLongitude(last.getLongitude());
+ }
+ }
+ return position;
+ }
+
+}