aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-11-09 07:55:45 -0800
committerAnton Tananaev <anton@traccar.org>2023-11-09 07:55:45 -0800
commitcd5413ae082a55e94d46f38a2a73f72eddb92aca (patch)
treea67bedd81e4e113a60deef516c30e43f6ab02bb4 /src
parentd57af42117c98a0c52d9bd776aa8d24af2dfafeb (diff)
downloadtrackermap-server-cd5413ae082a55e94d46f38a2a73f72eddb92aca.tar.gz
trackermap-server-cd5413ae082a55e94d46f38a2a73f72eddb92aca.tar.bz2
trackermap-server-cd5413ae082a55e94d46f38a2a73f72eddb92aca.zip
Update HERE geocoder
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/MainModule.java3
-rw-r--r--src/main/java/org/traccar/config/Keys.java7
-rw-r--r--src/main/java/org/traccar/geocoder/HereGeocoder.java58
-rw-r--r--src/test/java/org/traccar/geocoder/GeocoderTest.java4
4 files changed, 29 insertions, 43 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 9559b3a90..3fec4d1e6 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -200,7 +200,6 @@ public class MainModule extends AbstractModule {
if (config.getBoolean(Keys.GEOCODER_ENABLE)) {
String type = config.getString(Keys.GEOCODER_TYPE, "google");
String url = config.getString(Keys.GEOCODER_URL);
- String id = config.getString(Keys.GEOCODER_ID);
String key = config.getString(Keys.GEOCODER_KEY);
String language = config.getString(Keys.GEOCODER_LANGUAGE);
String formatString = config.getString(Keys.GEOCODER_FORMAT);
@@ -243,7 +242,7 @@ public class MainModule extends AbstractModule {
geocoder = new BanGeocoder(client, cacheSize, addressFormat);
break;
case "here":
- geocoder = new HereGeocoder(client, url, id, key, language, cacheSize, addressFormat);
+ geocoder = new HereGeocoder(client, url, key, language, cacheSize, addressFormat);
break;
case "mapmyindia":
geocoder = new MapmyIndiaGeocoder(client, url, key, cacheSize, addressFormat);
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 48dec863d..e7b07791f 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -1554,13 +1554,6 @@ public final class Keys {
List.of(KeyType.CONFIG));
/**
- * App id for use with Here provider.
- */
- public static final ConfigKey<String> GEOCODER_ID = new StringConfigKey(
- "geocoder.id",
- List.of(KeyType.CONFIG));
-
- /**
* Provider API key. Most providers require API keys.
*/
public static final ConfigKey<String> GEOCODER_KEY = new StringConfigKey(
diff --git a/src/main/java/org/traccar/geocoder/HereGeocoder.java b/src/main/java/org/traccar/geocoder/HereGeocoder.java
index 2d1bc1bf4..4767eabad 100644
--- a/src/main/java/org/traccar/geocoder/HereGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/HereGeocoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 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.
@@ -20,65 +20,59 @@ import jakarta.ws.rs.client.Client;
public class HereGeocoder extends JsonGeocoder {
- private static String formatUrl(String url, String id, String key, String language) {
+ private static String formatUrl(String url, String key, String language) {
if (url == null) {
- url = "https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json";
+ url = "https://revgeocode.search.hereapi.com/v1/revgeocode";
}
- url += "?mode=retrieveAddresses&maxresults=1";
- url += "&prox=%f,%f,0";
- url += "&app_id=" + id;
- url += "&app_code=" + key;
+ url += "?types=address&limit=1";
+ url += "&at=%f,%f";
url += "&apiKey=" + key;
if (language != null) {
- url += "&language=" + language;
+ url += "&lang=" + language;
}
return url;
}
public HereGeocoder(
- Client client, String url, String id, String key, String language,
+ Client client, String url, String key, String language,
int cacheSize, AddressFormat addressFormat) {
- super(client, formatUrl(url, id, key, language), cacheSize, addressFormat);
+ super(client, formatUrl(url, key, language), cacheSize, addressFormat);
}
@Override
public Address parseAddress(JsonObject json) {
JsonObject result = json
- .getJsonObject("Response")
- .getJsonArray("View")
+ .getJsonArray("items")
.getJsonObject(0)
- .getJsonArray("Result")
- .getJsonObject(0)
- .getJsonObject("Location")
- .getJsonObject("Address");
+ .getJsonObject("address");
if (result != null) {
Address address = new Address();
- if (result.containsKey("Label")) {
- address.setFormattedAddress(result.getString("Label"));
+ if (result.containsKey("label")) {
+ address.setFormattedAddress(result.getString("label"));
}
- if (result.containsKey("HouseNumber")) {
- address.setHouse(result.getString("HouseNumber"));
+ if (result.containsKey("houseNumber")) {
+ address.setHouse(result.getString("houseNumber"));
}
- if (result.containsKey("Street")) {
- address.setStreet(result.getString("Street"));
+ if (result.containsKey("street")) {
+ address.setStreet(result.getString("street"));
}
- if (result.containsKey("City")) {
- address.setSettlement(result.getString("City"));
+ if (result.containsKey("city")) {
+ address.setSettlement(result.getString("city"));
}
- if (result.containsKey("District")) {
- address.setDistrict(result.getString("District"));
+ if (result.containsKey("district")) {
+ address.setDistrict(result.getString("district"));
}
- if (result.containsKey("State")) {
- address.setState(result.getString("State"));
+ if (result.containsKey("state")) {
+ address.setState(result.getString("state"));
}
- if (result.containsKey("Country")) {
- address.setCountry(result.getString("Country").toUpperCase());
+ if (result.containsKey("countryCode")) {
+ address.setCountry(result.getString("countryCode").toUpperCase());
}
- if (result.containsKey("PostalCode")) {
- address.setPostcode(result.getString("PostalCode"));
+ if (result.containsKey("postalCode")) {
+ address.setPostcode(result.getString("postalCode"));
}
return address;
diff --git a/src/test/java/org/traccar/geocoder/GeocoderTest.java b/src/test/java/org/traccar/geocoder/GeocoderTest.java
index 1e1a98c1e..ef2dd062d 100644
--- a/src/test/java/org/traccar/geocoder/GeocoderTest.java
+++ b/src/test/java/org/traccar/geocoder/GeocoderTest.java
@@ -77,9 +77,9 @@ public class GeocoderTest {
@Disabled
@Test
public void testHere() {
- Geocoder geocoder = new HereGeocoder(client, null, "", "", null, 0, new AddressFormat());
+ Geocoder geocoder = new HereGeocoder(client, null, "aDc9qgsCpRbO9ioJIIAXzF6JYU7w8H5O260e9hsGrms", null, 0, new AddressFormat());
String address = geocoder.getAddress(48.8575, 2.2944, null);
- assertEquals("6 Avenue Gustave Eiffel, Paris, Île-de-France, FRA", address);
+ assertEquals("1 Tour Eiffel, Paris, Île-de-France, FRA", address);
}
@Disabled