diff options
author | Anton Tananaev <anton@traccar.org> | 2023-11-09 07:55:45 -0800 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-11-09 07:55:45 -0800 |
commit | cd5413ae082a55e94d46f38a2a73f72eddb92aca (patch) | |
tree | a67bedd81e4e113a60deef516c30e43f6ab02bb4 /src/main/java | |
parent | d57af42117c98a0c52d9bd776aa8d24af2dfafeb (diff) | |
download | trackermap-server-cd5413ae082a55e94d46f38a2a73f72eddb92aca.tar.gz trackermap-server-cd5413ae082a55e94d46f38a2a73f72eddb92aca.tar.bz2 trackermap-server-cd5413ae082a55e94d46f38a2a73f72eddb92aca.zip |
Update HERE geocoder
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/traccar/MainModule.java | 3 | ||||
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 7 | ||||
-rw-r--r-- | src/main/java/org/traccar/geocoder/HereGeocoder.java | 58 |
3 files changed, 27 insertions, 41 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; |