diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-08-08 10:31:49 +0300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-08-08 10:31:49 +0300 |
commit | ecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0 (patch) | |
tree | 9e4e98e2d35c36b2fcab3026169141fdc6ee2ba1 | |
parent | 5c0e9d5eff4f471837ad26aa763ac8b5dc7fc501 (diff) | |
download | trackermap-server-ecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0.tar.gz trackermap-server-ecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0.tar.bz2 trackermap-server-ecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0.zip |
Add coordinates filter (fix #2192)
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 9 | ||||
-rw-r--r-- | src/org/traccar/CoordinatesHandler.java | 51 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 31845290f..2b5028f33 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -44,6 +44,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { private int timeout; private FilterHandler filterHandler; + private CoordinatesHandler coordinatesHandler; private DistanceHandler distanceHandler; private ReverseGeocoderHandler reverseGeocoderHandler; private LocationProviderHandler locationProviderHandler; @@ -115,6 +116,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { filterHandler = new FilterHandler(); } + if (Context.getConfig().getBoolean("coordinates.filter")) { + coordinatesHandler = new CoordinatesHandler(); + } + if (Context.getReverseGeocoder() != null) { reverseGeocoderHandler = new ReverseGeocoderHandler( Context.getReverseGeocoder(), Context.getConfig().getBoolean("geocoder.processInvalidPositions")); @@ -188,6 +193,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { pipeline.addLast("filter", filterHandler); } + if (coordinatesHandler != null) { + pipeline.addLast("coordinatesHandler", coordinatesHandler); + } + if (Context.getDataManager() != null) { pipeline.addLast("dataHandler", new DefaultDataHandler()); } 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; + } + +} |