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/main/java') 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/main/java') 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/main/java') 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 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/main/java') 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