aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/config/Keys.java9
-rw-r--r--src/main/java/org/traccar/handler/GeolocationHandler.java7
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())) {