diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-11-11 09:21:45 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-11 09:21:45 +1300 |
commit | 204b1074ee57960775066c7c483d54bab8ebf279 (patch) | |
tree | bfec39fe84b547dac991f0d38cd69e9c64c688a6 /src/org/traccar/Context.java | |
parent | 92f00d0da0dafd08ccf2a623406963e61fcde276 (diff) | |
parent | 96d89e2e352f5cba70a346b1f71bfb3bd399556b (diff) | |
download | trackermap-server-204b1074ee57960775066c7c483d54bab8ebf279.tar.gz trackermap-server-204b1074ee57960775066c7c483d54bab8ebf279.tar.bz2 trackermap-server-204b1074ee57960775066c7c483d54bab8ebf279.zip |
Merge pull request #3632 from Abyss777/retry_geocoding
Retry geocoding for trips/stops
Diffstat (limited to 'src/org/traccar/Context.java')
-rw-r--r-- | src/org/traccar/Context.java | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index 3b24c6460..237da40c8 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -43,6 +43,7 @@ import org.traccar.database.StatisticsManager; import org.traccar.database.UsersManager; import org.traccar.events.MotionEventHandler; import org.traccar.events.OverspeedEventHandler; +import org.traccar.geocoder.AddressFormat; import org.traccar.geocoder.BingMapsGeocoder; import org.traccar.geocoder.FactualGeocoder; import org.traccar.geocoder.GeocodeFarmGeocoder; @@ -263,6 +264,41 @@ public final class Context { config.getDouble("event.motion.speedThreshold", 0.01)); } + public static Geocoder initGeocoder() { + String type = config.getString("geocoder.type", "google"); + String url = config.getString("geocoder.url"); + String key = config.getString("geocoder.key"); + String language = config.getString("geocoder.language"); + + String formatString = config.getString("geocoder.format"); + AddressFormat addressFormat; + if (formatString != null) { + addressFormat = new AddressFormat(formatString); + } else { + addressFormat = new AddressFormat(); + } + + int cacheSize = config.getInteger("geocoder.cacheSize"); + switch (type) { + case "nominatim": + return new NominatimGeocoder(url, key, language, cacheSize, addressFormat); + case "gisgraphy": + return new GisgraphyGeocoder(url, cacheSize, addressFormat); + case "mapquest": + return new MapQuestGeocoder(url, key, cacheSize, addressFormat); + case "opencage": + return new OpenCageGeocoder(url, key, cacheSize, addressFormat); + case "bingmaps": + return new BingMapsGeocoder(url, key, cacheSize, addressFormat); + case "factual": + return new FactualGeocoder(url, key, cacheSize, addressFormat); + case "geocodefarm": + return new GeocodeFarmGeocoder(key, language, cacheSize, addressFormat); + default: + return new GoogleGeocoder(key, language, cacheSize, addressFormat); + } + } + public static void init(String[] arguments) throws Exception { config = new Config(); @@ -298,38 +334,7 @@ public final class Context { identityManager = deviceManager; if (config.getBoolean("geocoder.enable")) { - String type = config.getString("geocoder.type", "google"); - String url = config.getString("geocoder.url"); - String key = config.getString("geocoder.key"); - String language = config.getString("geocoder.language"); - - int cacheSize = config.getInteger("geocoder.cacheSize"); - switch (type) { - case "nominatim": - geocoder = new NominatimGeocoder(url, key, language, cacheSize); - break; - case "gisgraphy": - geocoder = new GisgraphyGeocoder(url, cacheSize); - break; - case "mapquest": - geocoder = new MapQuestGeocoder(url, key, cacheSize); - break; - case "opencage": - geocoder = new OpenCageGeocoder(url, key, cacheSize); - break; - case "bingmaps": - geocoder = new BingMapsGeocoder(url, key, cacheSize); - break; - case "factual": - geocoder = new FactualGeocoder(url, key, cacheSize); - break; - case "geocodefarm": - geocoder = new GeocodeFarmGeocoder(key, language, cacheSize); - break; - default: - geocoder = new GoogleGeocoder(key, language, cacheSize); - break; - } + geocoder = initGeocoder(); } if (config.getBoolean("geolocation.enable")) { |