diff options
author | Anton Tananaev <anton@traccar.org> | 2023-10-16 07:38:12 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-10-16 07:38:12 -0700 |
commit | d3631eb7286338a0ea046a511aa5cbfce470c7b7 (patch) | |
tree | cd8baed039ced5f9fd0a78058551c7803fb0ca1a /src/main/java/org | |
parent | 33d01cda7bb678bb604404f18c8f4e66a40eaa55 (diff) | |
download | trackermap-server-d3631eb7286338a0ea046a511aa5cbfce470c7b7.tar.gz trackermap-server-d3631eb7286338a0ea046a511aa5cbfce470c7b7.tar.bz2 trackermap-server-d3631eb7286338a0ea046a511aa5cbfce470c7b7.zip |
Option to require Wi-Fi geolocation
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 9 | ||||
-rw-r--r-- | src/main/java/org/traccar/handler/GeolocationHandler.java | 7 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 15bfec09d..91063a8e0 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 - 2022 Anton Tananaev (anton@traccar.org) + * Copyright 2019 - 2023 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. @@ -1650,6 +1650,13 @@ public final class Keys { List.of(KeyType.CONFIG)); /** + * Process geolocation only when Wi-Fi information is available. This makes the result more accurate. + */ + public static final ConfigKey<Boolean> GEOLOCATION_REQUIRE_WIFI = new BooleanConfigKey( + "geolocation.requireWifi", + List.of(KeyType.CONFIG)); + + /** * Default MCC value to use if device doesn't report MCC. */ public static final ConfigKey<Integer> GEOLOCATION_MCC = new IntegerConfigKey( diff --git a/src/main/java/org/traccar/handler/GeolocationHandler.java b/src/main/java/org/traccar/handler/GeolocationHandler.java index e7389f22d..a54ea03e3 100644 --- a/src/main/java/org/traccar/handler/GeolocationHandler.java +++ b/src/main/java/org/traccar/handler/GeolocationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2023 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. @@ -37,6 +37,7 @@ public class GeolocationHandler extends ChannelInboundHandlerAdapter { private final StatisticsManager statisticsManager; private final boolean processInvalidPositions; private final boolean reuse; + private final boolean requireWifi; public GeolocationHandler( Config config, GeolocationProvider geolocationProvider, CacheManager cacheManager, @@ -46,6 +47,7 @@ public class GeolocationHandler extends ChannelInboundHandlerAdapter { this.statisticsManager = statisticsManager; processInvalidPositions = config.getBoolean(Keys.GEOLOCATION_PROCESS_INVALID_POSITIONS); reuse = config.getBoolean(Keys.GEOLOCATION_REUSE); + requireWifi = config.getBoolean(Keys.GEOLOCATION_REQUIRE_WIFI); } @Override @@ -53,7 +55,8 @@ public class GeolocationHandler extends ChannelInboundHandlerAdapter { if (message instanceof Position) { final Position position = (Position) message; if ((position.getOutdated() || processInvalidPositions && !position.getValid()) - && position.getNetwork() != null) { + && position.getNetwork() != null + && (!requireWifi || position.getNetwork().getWifiAccessPoints() != null)) { if (reuse) { Position lastPosition = cacheManager.getPosition(position.getDeviceId()); if (lastPosition != null && position.getNetwork().equals(lastPosition.getNetwork())) { |