aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/geocoder
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/geocoder')
-rw-r--r--src/main/java/org/traccar/geocoder/BanGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/BingMapsGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/FactualGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/GeoapifyGeocoder.java82
-rw-r--r--src/main/java/org/traccar/geocoder/GeocodeFarmGeocoder.java6
-rw-r--r--src/main/java/org/traccar/geocoder/GeocodeXyzGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/Geocoder.java4
-rw-r--r--src/main/java/org/traccar/geocoder/GisgraphyGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/GoogleGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/HereGeocoder.java6
-rw-r--r--src/main/java/org/traccar/geocoder/JsonGeocoder.java22
-rw-r--r--src/main/java/org/traccar/geocoder/LocationIqGeocoder.java29
-rw-r--r--src/main/java/org/traccar/geocoder/MapQuestGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/MapTilerGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/MapboxGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/MapmyIndiaGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/NominatimGeocoder.java6
-rw-r--r--src/main/java/org/traccar/geocoder/OpenCageGeocoder.java11
-rw-r--r--src/main/java/org/traccar/geocoder/PositionStackGeocoder.java5
-rw-r--r--src/main/java/org/traccar/geocoder/TestGeocoder.java36
-rw-r--r--src/main/java/org/traccar/geocoder/TomTomGeocoder.java5
21 files changed, 221 insertions, 41 deletions
diff --git a/src/main/java/org/traccar/geocoder/BanGeocoder.java b/src/main/java/org/traccar/geocoder/BanGeocoder.java
index b1f0900a4..f878a8bab 100644
--- a/src/main/java/org/traccar/geocoder/BanGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/BanGeocoder.java
@@ -22,11 +22,12 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class BanGeocoder extends JsonGeocoder {
- public BanGeocoder(int cacheSize, AddressFormat addressFormat) {
- super("https://api-adresse.data.gouv.fr/reverse/?lat=%f&lon=%f", cacheSize, addressFormat);
+ public BanGeocoder(Client client, int cacheSize, AddressFormat addressFormat) {
+ super(client, "https://api-adresse.data.gouv.fr/reverse/?lat=%f&lon=%f", cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/BingMapsGeocoder.java b/src/main/java/org/traccar/geocoder/BingMapsGeocoder.java
index 32a26ee0c..01e33c2ea 100644
--- a/src/main/java/org/traccar/geocoder/BingMapsGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/BingMapsGeocoder.java
@@ -18,11 +18,12 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class BingMapsGeocoder extends JsonGeocoder {
- public BingMapsGeocoder(String url, String key, int cacheSize, AddressFormat addressFormat) {
- super(url + "/Locations/%f,%f?key=" + key + "&include=ciso2", cacheSize, addressFormat);
+ public BingMapsGeocoder(Client client, String url, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, url + "/Locations/%f,%f?key=" + key + "&include=ciso2", cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/FactualGeocoder.java b/src/main/java/org/traccar/geocoder/FactualGeocoder.java
index f540eb8fe..384f46b0e 100644
--- a/src/main/java/org/traccar/geocoder/FactualGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/FactualGeocoder.java
@@ -17,6 +17,7 @@
package org.traccar.geocoder;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class FactualGeocoder extends JsonGeocoder {
@@ -28,8 +29,8 @@ public class FactualGeocoder extends JsonGeocoder {
return url;
}
- public FactualGeocoder(String url, String key, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(url, key), cacheSize, addressFormat);
+ public FactualGeocoder(Client client, String url, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(url, key), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/GeoapifyGeocoder.java b/src/main/java/org/traccar/geocoder/GeoapifyGeocoder.java
new file mode 100644
index 000000000..4748d6a2c
--- /dev/null
+++ b/src/main/java/org/traccar/geocoder/GeoapifyGeocoder.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2022 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.
+ * 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.geocoder;
+
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
+
+public class GeoapifyGeocoder extends JsonGeocoder {
+
+ private static String formatUrl(String key, String language) {
+ String url = "https://api.geoapify.com/v1/geocode/reverse?format=json&lat=%f&lon=%f";
+ if (key != null) {
+ url += "&apiKey=" + key;
+ }
+ if (language != null) {
+ url += "&lang=" + language;
+ }
+ return url;
+ }
+
+ public GeoapifyGeocoder(Client client, String key, String language, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(key, language), cacheSize, addressFormat);
+ }
+
+ @Override
+ public Address parseAddress(JsonObject json) {
+ JsonArray results = json.getJsonArray("results");
+ if (results.size() > 0) {
+ JsonObject result = results.getJsonObject(0);
+
+ Address address = new Address();
+
+ if (json.containsKey("formatted")) {
+ address.setFormattedAddress(json.getString("formatted"));
+ }
+
+ if (result.containsKey("housenumber")) {
+ address.setHouse(result.getString("housenumber"));
+ }
+ if (result.containsKey("street")) {
+ address.setStreet(result.getString("street"));
+ }
+ if (result.containsKey("suburb")) {
+ address.setSuburb(result.getString("suburb"));
+ }
+ if (result.containsKey("city")) {
+ address.setSettlement(result.getString("city"));
+ }
+ if (result.containsKey("district")) {
+ address.setDistrict(result.getString("district"));
+ }
+ if (result.containsKey("state")) {
+ address.setState(result.getString("state"));
+ }
+ if (result.containsKey("country_code")) {
+ address.setCountry(result.getString("country_code").toUpperCase());
+ }
+ if (result.containsKey("postcode")) {
+ address.setPostcode(result.getString("postcode"));
+ }
+
+ return address;
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/traccar/geocoder/GeocodeFarmGeocoder.java b/src/main/java/org/traccar/geocoder/GeocodeFarmGeocoder.java
index 39a3300a0..2af95910f 100644
--- a/src/main/java/org/traccar/geocoder/GeocodeFarmGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/GeocodeFarmGeocoder.java
@@ -16,6 +16,7 @@
package org.traccar.geocoder;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class GeocodeFarmGeocoder extends JsonGeocoder {
@@ -30,8 +31,9 @@ public class GeocodeFarmGeocoder extends JsonGeocoder {
}
return url;
}
- public GeocodeFarmGeocoder(String key, String language, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(key, language), cacheSize, addressFormat);
+ public GeocodeFarmGeocoder(
+ Client client, String key, String language, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(key, language), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/GeocodeXyzGeocoder.java b/src/main/java/org/traccar/geocoder/GeocodeXyzGeocoder.java
index aca360c3d..96491ece3 100644
--- a/src/main/java/org/traccar/geocoder/GeocodeXyzGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/GeocodeXyzGeocoder.java
@@ -16,6 +16,7 @@
package org.traccar.geocoder;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class GeocodeXyzGeocoder extends JsonGeocoder {
@@ -27,8 +28,8 @@ public class GeocodeXyzGeocoder extends JsonGeocoder {
return url;
}
- public GeocodeXyzGeocoder(String key, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(key), cacheSize, addressFormat);
+ public GeocodeXyzGeocoder(Client client, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(key), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/Geocoder.java b/src/main/java/org/traccar/geocoder/Geocoder.java
index 587a27520..f4abe871a 100644
--- a/src/main/java/org/traccar/geocoder/Geocoder.java
+++ b/src/main/java/org/traccar/geocoder/Geocoder.java
@@ -15,6 +15,8 @@
*/
package org.traccar.geocoder;
+import org.traccar.database.StatisticsManager;
+
public interface Geocoder {
interface ReverseGeocoderCallback {
@@ -27,4 +29,6 @@ public interface Geocoder {
String getAddress(double latitude, double longitude, ReverseGeocoderCallback callback);
+ void setStatisticsManager(StatisticsManager statisticsManager);
+
}
diff --git a/src/main/java/org/traccar/geocoder/GisgraphyGeocoder.java b/src/main/java/org/traccar/geocoder/GisgraphyGeocoder.java
index b4881a006..0589eb000 100644
--- a/src/main/java/org/traccar/geocoder/GisgraphyGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/GisgraphyGeocoder.java
@@ -16,6 +16,7 @@
package org.traccar.geocoder;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class GisgraphyGeocoder extends JsonGeocoder {
@@ -27,8 +28,8 @@ public class GisgraphyGeocoder extends JsonGeocoder {
return url;
}
- public GisgraphyGeocoder(String url, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(url), cacheSize, addressFormat);
+ public GisgraphyGeocoder(Client client, String url, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(url), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/GoogleGeocoder.java b/src/main/java/org/traccar/geocoder/GoogleGeocoder.java
index 9494cab45..4d9ec8f36 100644
--- a/src/main/java/org/traccar/geocoder/GoogleGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/GoogleGeocoder.java
@@ -18,6 +18,7 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonString;
+import javax.ws.rs.client.Client;
public class GoogleGeocoder extends JsonGeocoder {
@@ -32,8 +33,8 @@ public class GoogleGeocoder extends JsonGeocoder {
return url;
}
- public GoogleGeocoder(String key, String language, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(key, language), cacheSize, addressFormat);
+ public GoogleGeocoder(Client client, String key, String language, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(key, language), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/HereGeocoder.java b/src/main/java/org/traccar/geocoder/HereGeocoder.java
index 40390e65b..eb639995e 100644
--- a/src/main/java/org/traccar/geocoder/HereGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/HereGeocoder.java
@@ -16,6 +16,7 @@
package org.traccar.geocoder;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class HereGeocoder extends JsonGeocoder {
@@ -35,8 +36,9 @@ public class HereGeocoder extends JsonGeocoder {
}
public HereGeocoder(
- String url, String id, String key, String language, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(url, id, key, language), cacheSize, addressFormat);
+ Client client, String url, String id, String key, String language,
+ int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(url, id, key, language), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/JsonGeocoder.java b/src/main/java/org/traccar/geocoder/JsonGeocoder.java
index f20aa79d6..6105e8cfd 100644
--- a/src/main/java/org/traccar/geocoder/JsonGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/JsonGeocoder.java
@@ -17,13 +17,11 @@ package org.traccar.geocoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.traccar.Context;
-import org.traccar.Main;
import org.traccar.database.StatisticsManager;
import javax.json.JsonObject;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.Client;
import javax.ws.rs.client.InvocationCallback;
import java.util.AbstractMap;
import java.util.Collections;
@@ -34,16 +32,19 @@ public abstract class JsonGeocoder implements Geocoder {
private static final Logger LOGGER = LoggerFactory.getLogger(JsonGeocoder.class);
+ private final Client client;
private final String url;
private final AddressFormat addressFormat;
+ private StatisticsManager statisticsManager;
private Map<Map.Entry<Double, Double>, String> cache;
- public JsonGeocoder(String url, final int cacheSize, AddressFormat addressFormat) {
+ public JsonGeocoder(Client client, String url, final int cacheSize, AddressFormat addressFormat) {
+ this.client = client;
this.url = url;
this.addressFormat = addressFormat;
if (cacheSize > 0) {
- this.cache = Collections.synchronizedMap(new LinkedHashMap<Map.Entry<Double, Double>, String>() {
+ this.cache = Collections.synchronizedMap(new LinkedHashMap<>() {
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > cacheSize;
@@ -52,6 +53,11 @@ public abstract class JsonGeocoder implements Geocoder {
}
}
+ @Override
+ public void setStatisticsManager(StatisticsManager statisticsManager) {
+ this.statisticsManager = statisticsManager;
+ }
+
protected String readValue(JsonObject object, String key) {
if (object.containsKey(key) && !object.isNull(key)) {
return object.getString(key);
@@ -97,11 +103,11 @@ public abstract class JsonGeocoder implements Geocoder {
}
}
- if (Main.getInjector() != null) {
- Main.getInjector().getInstance(StatisticsManager.class).registerGeocoderRequest();
+ if (statisticsManager != null) {
+ statisticsManager.registerGeocoderRequest();
}
- Invocation.Builder request = Context.getClient().target(String.format(url, latitude, longitude)).request();
+ var request = client.target(String.format(url, latitude, longitude)).request();
if (callback != null) {
request.async().get(new InvocationCallback<JsonObject>() {
diff --git a/src/main/java/org/traccar/geocoder/LocationIqGeocoder.java b/src/main/java/org/traccar/geocoder/LocationIqGeocoder.java
new file mode 100644
index 000000000..f2ffe02d6
--- /dev/null
+++ b/src/main/java/org/traccar/geocoder/LocationIqGeocoder.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2022 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.
+ * 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.geocoder;
+
+import javax.ws.rs.client.Client;
+
+public class LocationIqGeocoder extends NominatimGeocoder {
+
+ private static final String DEFAULT_URL = "https://us1.locationiq.com/v1/reverse.php";
+
+ public LocationIqGeocoder(
+ Client client, String url, String key, String language, int cacheSize, AddressFormat addressFormat) {
+ super(client, url != null ? url : DEFAULT_URL, key, language, cacheSize, addressFormat);
+ }
+
+}
diff --git a/src/main/java/org/traccar/geocoder/MapQuestGeocoder.java b/src/main/java/org/traccar/geocoder/MapQuestGeocoder.java
index 8dc3f76f0..3f2554c6e 100644
--- a/src/main/java/org/traccar/geocoder/MapQuestGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/MapQuestGeocoder.java
@@ -18,6 +18,7 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class MapQuestGeocoder extends JsonGeocoder {
@@ -29,8 +30,8 @@ public class MapQuestGeocoder extends JsonGeocoder {
return url;
}
- public MapQuestGeocoder(String url, String key, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(url, key), cacheSize, addressFormat);
+ public MapQuestGeocoder(Client client, String url, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(url, key), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/MapTilerGeocoder.java b/src/main/java/org/traccar/geocoder/MapTilerGeocoder.java
index 6b688a6e8..203f5f99b 100644
--- a/src/main/java/org/traccar/geocoder/MapTilerGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/MapTilerGeocoder.java
@@ -17,11 +17,12 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class MapTilerGeocoder extends JsonGeocoder {
- public MapTilerGeocoder(String key, int cacheSize, AddressFormat addressFormat) {
- super("https://api.maptiler.com/geocoding/%2$f,%1$f.json?key=" + key, cacheSize, addressFormat);
+ public MapTilerGeocoder(Client client, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, "https://api.maptiler.com/geocoding/%2$f,%1$f.json?key=" + key, cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/MapboxGeocoder.java b/src/main/java/org/traccar/geocoder/MapboxGeocoder.java
index 9b987c9d8..72bfb53f5 100644
--- a/src/main/java/org/traccar/geocoder/MapboxGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/MapboxGeocoder.java
@@ -18,6 +18,7 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonString;
+import javax.ws.rs.client.Client;
public class MapboxGeocoder extends JsonGeocoder {
@@ -25,8 +26,8 @@ public class MapboxGeocoder extends JsonGeocoder {
return "https://api.mapbox.com/geocoding/v5/mapbox.places/%2$f,%1$f.json?access_token=" + key;
}
- public MapboxGeocoder(String key, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(key), cacheSize, addressFormat);
+ public MapboxGeocoder(Client client, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(key), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/MapmyIndiaGeocoder.java b/src/main/java/org/traccar/geocoder/MapmyIndiaGeocoder.java
index 2b70708a1..dea295cca 100644
--- a/src/main/java/org/traccar/geocoder/MapmyIndiaGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/MapmyIndiaGeocoder.java
@@ -17,11 +17,12 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class MapmyIndiaGeocoder extends JsonGeocoder {
- public MapmyIndiaGeocoder(String url, String key, int cacheSize, AddressFormat addressFormat) {
- super(url + "/" + key + "/rev_geocode?lat=%f&lng=%f", cacheSize, addressFormat);
+ public MapmyIndiaGeocoder(Client client, String url, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, url + "/" + key + "/rev_geocode?lat=%f&lng=%f", cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/NominatimGeocoder.java b/src/main/java/org/traccar/geocoder/NominatimGeocoder.java
index 8db25bf15..b731549f7 100644
--- a/src/main/java/org/traccar/geocoder/NominatimGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/NominatimGeocoder.java
@@ -16,6 +16,7 @@
package org.traccar.geocoder;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class NominatimGeocoder extends JsonGeocoder {
@@ -33,8 +34,9 @@ public class NominatimGeocoder extends JsonGeocoder {
return url;
}
- public NominatimGeocoder(String url, String key, String language, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(url, key, language), cacheSize, addressFormat);
+ public NominatimGeocoder(
+ Client client, String url, String key, String language, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(url, key, language), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java b/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java
index 56161e52c..fb61440aa 100644
--- a/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java
@@ -18,19 +18,24 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class OpenCageGeocoder extends JsonGeocoder {
- private static String formatUrl(String url, String key) {
+ private static String formatUrl(String url, String key, String language) {
if (url == null) {
url = "https://api.opencagedata.com/geocode/v1";
}
url += "/json?q=%f,%f&no_annotations=1&key=" + key;
+ if (language != null) {
+ url += "&language=" + language;
+ }
return url;
}
- public OpenCageGeocoder(String url, String key, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(url, key), cacheSize, addressFormat);
+ public OpenCageGeocoder(
+ Client client, String url, String key, String language, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(url, key, language), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/PositionStackGeocoder.java b/src/main/java/org/traccar/geocoder/PositionStackGeocoder.java
index 2674a68ca..9778d9eda 100644
--- a/src/main/java/org/traccar/geocoder/PositionStackGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/PositionStackGeocoder.java
@@ -17,6 +17,7 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class PositionStackGeocoder extends JsonGeocoder {
@@ -24,8 +25,8 @@ public class PositionStackGeocoder extends JsonGeocoder {
return "http://api.positionstack.com/v1/reverse?access_key=" + key + "&query=%f,%f";
}
- public PositionStackGeocoder(String key, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(key), cacheSize, addressFormat);
+ public PositionStackGeocoder(Client client, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(key), cacheSize, addressFormat);
}
@Override
diff --git a/src/main/java/org/traccar/geocoder/TestGeocoder.java b/src/main/java/org/traccar/geocoder/TestGeocoder.java
new file mode 100644
index 000000000..259f13c6c
--- /dev/null
+++ b/src/main/java/org/traccar/geocoder/TestGeocoder.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2022 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.
+ * 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.geocoder;
+
+import org.traccar.database.StatisticsManager;
+
+public class TestGeocoder implements Geocoder {
+
+ @Override
+ public void setStatisticsManager(StatisticsManager statisticsManager) {
+ }
+
+ @Override
+ public String getAddress(double latitude, double longitude, ReverseGeocoderCallback callback) {
+ String address = String.format("Location %f, %f", latitude, longitude);
+ if (callback != null) {
+ callback.onSuccess(address);
+ return null;
+ }
+ return address;
+ }
+
+}
diff --git a/src/main/java/org/traccar/geocoder/TomTomGeocoder.java b/src/main/java/org/traccar/geocoder/TomTomGeocoder.java
index 232b24396..9bb36efc2 100644
--- a/src/main/java/org/traccar/geocoder/TomTomGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/TomTomGeocoder.java
@@ -17,6 +17,7 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
public class TomTomGeocoder extends JsonGeocoder {
@@ -28,8 +29,8 @@ public class TomTomGeocoder extends JsonGeocoder {
return url;
}
- public TomTomGeocoder(String url, String key, int cacheSize, AddressFormat addressFormat) {
- super(formatUrl(url, key), cacheSize, addressFormat);
+ public TomTomGeocoder(Client client, String url, String key, int cacheSize, AddressFormat addressFormat) {
+ super(client, formatUrl(url, key), cacheSize, addressFormat);
}
@Override