From c84ab2c13e5529c34e0acf48304618659b427985 Mon Sep 17 00:00:00 2001 From: Ed Freyfogle Date: Thu, 24 Mar 2022 11:28:14 +0100 Subject: support language param, if null defaults to "en" --- src/main/java/org/traccar/geocoder/OpenCageGeocoder.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java b/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java index 56161e52c..18cf3a715 100644 --- a/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java +++ b/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java @@ -21,16 +21,21 @@ import javax.json.JsonObject; 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; + } else { + url += "&language=en"; + } return url; } - public OpenCageGeocoder(String url, String key, int cacheSize, AddressFormat addressFormat) { - super(formatUrl(url, key), cacheSize, addressFormat); + public OpenCageGeocoder(String url, String key, String language, int cacheSize, AddressFormat addressFormat) { + super(formatUrl(url, key, language), cacheSize, addressFormat); } @Override -- cgit v1.2.3 From be44289a93399b74a53797d992d994f7df6187d2 Mon Sep 17 00:00:00 2001 From: Ed Freyfogle Date: Thu, 24 Mar 2022 11:28:36 +0100 Subject: pass language to OpenCageGeocoder --- src/main/java/org/traccar/MainModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index d72e04588..842f7e3ce 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -181,7 +181,7 @@ public class MainModule extends AbstractModule { case "mapquest": return new MapQuestGeocoder(url, key, cacheSize, addressFormat); case "opencage": - return new OpenCageGeocoder(url, key, cacheSize, addressFormat); + return new OpenCageGeocoder(url, key, language, cacheSize, addressFormat); case "bingmaps": return new BingMapsGeocoder(url, key, cacheSize, addressFormat); case "factual": -- cgit v1.2.3 From eef38a4bf97a29873e29972b8f1fc7cdc4f9e927 Mon Sep 17 00:00:00 2001 From: Ed Freyfogle Date: Thu, 24 Mar 2022 11:30:08 +0100 Subject: change if logic to be same as url test --- src/main/java/org/traccar/geocoder/OpenCageGeocoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java b/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java index 18cf3a715..c4a82b03c 100644 --- a/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java +++ b/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java @@ -26,10 +26,10 @@ public class OpenCageGeocoder extends JsonGeocoder { url = "https://api.opencagedata.com/geocode/v1"; } url += "/json?q=%f,%f&no_annotations=1&key=" + key; - if (language != null) { - url += "&language=" + language; - } else { + if (language == null) { url += "&language=en"; + } else { + url += "&language=" + language; } return url; } -- cgit v1.2.3 From d65a3af95e2877b8f0fcb7f44cbfbd8b4f987622 Mon Sep 17 00:00:00 2001 From: Ed Freyfogle Date: Thu, 24 Mar 2022 11:32:25 +0100 Subject: pass language param to OpenCageGeocoder --- src/test/java/org/traccar/geocoder/GeocoderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/java/org/traccar/geocoder/GeocoderTest.java b/src/test/java/org/traccar/geocoder/GeocoderTest.java index 9134194f2..52dac625a 100644 --- a/src/test/java/org/traccar/geocoder/GeocoderTest.java +++ b/src/test/java/org/traccar/geocoder/GeocoderTest.java @@ -41,7 +41,7 @@ public class GeocoderTest { @Test public void testOpenCage() { Geocoder geocoder = new OpenCageGeocoder( - "http://api.opencagedata.com/geocode/v1", "SECRET", 0, new AddressFormat()); + "http://api.opencagedata.com/geocode/v1", "SECRET", "en", 0, new AddressFormat()); String address = geocoder.getAddress(34.116302, -118.051519, null); assertEquals("Charleston Road, California, US", address); } -- cgit v1.2.3 From f46a0471e9531febf33072adda9414e290354911 Mon Sep 17 00:00:00 2001 From: Ed Freyfogle Date: Thu, 24 Mar 2022 22:29:46 +0100 Subject: test with null instead of "en" --- src/test/java/org/traccar/geocoder/GeocoderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/java/org/traccar/geocoder/GeocoderTest.java b/src/test/java/org/traccar/geocoder/GeocoderTest.java index 52dac625a..91431fd6a 100644 --- a/src/test/java/org/traccar/geocoder/GeocoderTest.java +++ b/src/test/java/org/traccar/geocoder/GeocoderTest.java @@ -41,7 +41,7 @@ public class GeocoderTest { @Test public void testOpenCage() { Geocoder geocoder = new OpenCageGeocoder( - "http://api.opencagedata.com/geocode/v1", "SECRET", "en", 0, new AddressFormat()); + "http://api.opencagedata.com/geocode/v1", "SECRET", null, 0, new AddressFormat()); String address = geocoder.getAddress(34.116302, -118.051519, null); assertEquals("Charleston Road, California, US", address); } -- cgit v1.2.3 From 83af89dfe56753ab932014b89646c17577ba913d Mon Sep 17 00:00:00 2001 From: Ed Freyfogle Date: Thu, 24 Mar 2022 22:37:01 +0100 Subject: changed to be same as in Nominatim.java --- src/main/java/org/traccar/geocoder/OpenCageGeocoder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java b/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java index c4a82b03c..bbcc00cd0 100644 --- a/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java +++ b/src/main/java/org/traccar/geocoder/OpenCageGeocoder.java @@ -26,9 +26,7 @@ public class OpenCageGeocoder extends JsonGeocoder { url = "https://api.opencagedata.com/geocode/v1"; } url += "/json?q=%f,%f&no_annotations=1&key=" + key; - if (language == null) { - url += "&language=en"; - } else { + if (language != null) { url += "&language=" + language; } return url; -- cgit v1.2.3