aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/Context.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-11-08 15:43:13 +0500
committerAbyss777 <abyss@fox5.ru>2017-11-08 15:43:13 +0500
commit404044342a9fc9891366fa4378b4b1330cbca6c3 (patch)
tree98a2bfc2b6998e006f874d30ee9976c68345fee1 /src/org/traccar/Context.java
parent92f00d0da0dafd08ccf2a623406963e61fcde276 (diff)
downloadtrackermap-server-404044342a9fc9891366fa4378b4b1330cbca6c3.tar.gz
trackermap-server-404044342a9fc9891366fa4378b4b1330cbca6c3.tar.bz2
trackermap-server-404044342a9fc9891366fa4378b4b1330cbca6c3.zip
- Implement synchronous geocoding
- Implement retry geocoding for trips/stops reports - Implement API for revers geocoding
Diffstat (limited to 'src/org/traccar/Context.java')
-rw-r--r--src/org/traccar/Context.java71
1 files changed, 38 insertions, 33 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 3b24c6460..0671f1d29 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();
@@ -297,39 +333,8 @@ 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;
- }
+ if (config.getBoolean("geocoder.enable") || config.getBoolean("report.retryGeocoding")) {
+ geocoder = initGeocoder();
}
if (config.getBoolean("geolocation.enable")) {