diff options
Diffstat (limited to 'src')
4 files changed, 18 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 6ed240d2c..9559b3a90 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -303,7 +303,7 @@ public class MainModule extends AbstractModule { switch (type) { case "overpass": default: - return new OverpassSpeedLimitProvider(client, url); + return new OverpassSpeedLimitProvider(config, client, url); } } return null; diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 27f5f0921..23a983e7b 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -1678,6 +1678,14 @@ public final class Keys { List.of(KeyType.CONFIG)); /** + * Search radius for speed limit. Value is in meters. Default value is 100. + */ + public static final ConfigKey<Integer> SPEED_LIMIT_ACCURACY = new IntegerConfigKey( + "speedLimit.accuracy", + List.of(KeyType.CONFIG), + 100); + + /** * Override latitude sign / hemisphere. Useful in cases where value is incorrect because of device bug. Value can be * N for North or S for South. */ diff --git a/src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java b/src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java index 60ad65f9e..a25eedb2c 100644 --- a/src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java +++ b/src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 - 2022 Anton Tananaev (anton@traccar.org) + * Copyright 2020 - 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. @@ -15,6 +15,8 @@ */ package org.traccar.speedlimit; +import org.traccar.config.Config; +import org.traccar.config.Keys; import org.traccar.helper.UnitsConverter; import jakarta.json.JsonArray; @@ -28,9 +30,10 @@ public class OverpassSpeedLimitProvider implements SpeedLimitProvider { private final Client client; private final String url; - public OverpassSpeedLimitProvider(Client client, String url) { + public OverpassSpeedLimitProvider(Config config, Client client, String url) { + int accuracy = config.getInteger(Keys.SPEED_LIMIT_ACCURACY); this.client = client; - this.url = url + "?data=[out:json];way[maxspeed](around:100.0,%f,%f);out%%20tags;"; + this.url = url + "?data=[out:json];way[maxspeed](around:" + accuracy + ",%f,%f);out%%20tags;"; } private Double parseSpeed(String value) { diff --git a/src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java b/src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java index a59d1ce91..dbdf85420 100644 --- a/src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java +++ b/src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; +import org.traccar.config.Config; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -16,7 +17,8 @@ public class OverpassSpeedLimitProviderTest { @Disabled @Test public void testOverpass() throws Exception { - SpeedLimitProvider provider = new OverpassSpeedLimitProvider(client, "http://8.8.8.8/api/interpreter"); + var config = new Config(); + SpeedLimitProvider provider = new OverpassSpeedLimitProvider(config, client, "http://8.8.8.8/api/interpreter"); provider.getSpeedLimit(34.74767, -82.48098, new SpeedLimitProvider.SpeedLimitProviderCallback() { @Override |