diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-04-29 16:12:19 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-04-29 16:12:57 +1200 |
commit | 6c82282da3b35b2acf46f69655cd0d097058af24 (patch) | |
tree | a8c802590896ed7c49e374167a8a7212ef6bb06b /src/org/traccar/GeocoderHandler.java | |
parent | 4f235bcac5b13733684fed8e0ef05968123f6e10 (diff) | |
download | trackermap-server-6c82282da3b35b2acf46f69655cd0d097058af24.tar.gz trackermap-server-6c82282da3b35b2acf46f69655cd0d097058af24.tar.bz2 trackermap-server-6c82282da3b35b2acf46f69655cd0d097058af24.zip |
Save more statistics info
Diffstat (limited to 'src/org/traccar/GeocoderHandler.java')
-rw-r--r-- | src/org/traccar/GeocoderHandler.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/org/traccar/GeocoderHandler.java b/src/org/traccar/GeocoderHandler.java index 8933cadac..c5f4d2f9a 100644 --- a/src/org/traccar/GeocoderHandler.java +++ b/src/org/traccar/GeocoderHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.traccar.geocoder.AddressFormat; import org.traccar.geocoder.Geocoder; +import org.traccar.helper.DistanceCalculator; import org.traccar.helper.Log; import org.traccar.model.Position; @@ -30,6 +31,7 @@ public class GeocoderHandler implements ChannelUpstreamHandler { private final Geocoder geocoder; private final boolean processInvalidPositions; private final AddressFormat addressFormat; + private final int geocoderReuseDistance; public GeocoderHandler(Geocoder geocoder, boolean processInvalidPositions) { this.geocoder = geocoder; @@ -41,6 +43,8 @@ public class GeocoderHandler implements ChannelUpstreamHandler { } else { addressFormat = new AddressFormat(); } + + geocoderReuseDistance = Context.getConfig().getInteger("geocoder.reuseDistance", 0); } @Override @@ -55,6 +59,22 @@ public class GeocoderHandler implements ChannelUpstreamHandler { if (message instanceof Position) { final Position position = (Position) message; if (processInvalidPositions || position.getValid()) { + if (geocoderReuseDistance != 0) { + Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); + if (lastPosition != null && lastPosition.getAddress() != null) { + double distance = DistanceCalculator.distance( + position.getLatitude(), position.getLongitude(), + lastPosition.getLatitude(), lastPosition.getLongitude()); + if (distance <= geocoderReuseDistance) { + position.setAddress(lastPosition.getAddress()); + Channels.fireMessageReceived(ctx, position, event.getRemoteAddress()); + return; + } + } + } + + Context.getStatisticsManager().registerGeocoderRequest(); + geocoder.getAddress(addressFormat, position.getLatitude(), position.getLongitude(), new Geocoder.ReverseGeocoderCallback() { @Override |