diff options
Diffstat (limited to 'src/org/traccar/geocoder')
-rw-r--r-- | src/org/traccar/geocoder/Address.java | 100 | ||||
-rw-r--r-- | src/org/traccar/geocoder/AddressFormat.java | 80 | ||||
-rw-r--r-- | src/org/traccar/geocoder/BingMapsGeocoder.java | 59 | ||||
-rw-r--r-- | src/org/traccar/geocoder/FactualGeocoder.java | 57 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GeocodeFarmGeocoder.java | 66 | ||||
-rw-r--r-- | src/org/traccar/geocoder/Geocoder.java | 30 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GeocoderException.java | 24 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GisgraphyGeocoder.java | 52 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GoogleGeocoder.java | 89 | ||||
-rw-r--r-- | src/org/traccar/geocoder/JsonGeocoder.java | 89 | ||||
-rw-r--r-- | src/org/traccar/geocoder/MapQuestGeocoder.java | 62 | ||||
-rw-r--r-- | src/org/traccar/geocoder/NominatimGeocoder.java | 87 | ||||
-rw-r--r-- | src/org/traccar/geocoder/OpenCageGeocoder.java | 73 |
13 files changed, 0 insertions, 868 deletions
diff --git a/src/org/traccar/geocoder/Address.java b/src/org/traccar/geocoder/Address.java deleted file mode 100644 index d542d1b19..000000000 --- a/src/org/traccar/geocoder/Address.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -public class Address { - - private String postcode; - - public String getPostcode() { - return postcode; - } - - public void setPostcode(String postcode) { - this.postcode = postcode; - } - - private String country; - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - private String state; - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - private String district; - - public String getDistrict() { - return district; - } - - public void setDistrict(String district) { - this.district = district; - } - - private String settlement; - - public String getSettlement() { - return settlement; - } - - public void setSettlement(String settlement) { - this.settlement = settlement; - } - - private String suburb; - - public String getSuburb() { - return suburb; - } - - public void setSuburb(String suburb) { - this.suburb = suburb; - } - - private String street; - - public String getStreet() { - return street; - } - - public void setStreet(String street) { - this.street = street; - } - - private String house; - - public String getHouse() { - return house; - } - - public void setHouse(String house) { - this.house = house; - } - -} diff --git a/src/org/traccar/geocoder/AddressFormat.java b/src/org/traccar/geocoder/AddressFormat.java deleted file mode 100644 index 0800d6dcc..000000000 --- a/src/org/traccar/geocoder/AddressFormat.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import java.text.FieldPosition; -import java.text.Format; -import java.text.ParsePosition; - -/** - * Available parameters: - * - * %p - postcode - * %c - country - * %s - state - * %d - district - * %t - settlement (town) - * %u - suburb - * %r - street (road) - * %h - house - * - */ -public class AddressFormat extends Format { - - private final String format; - - public AddressFormat() { - this("%h %r, %t, %s, %c"); - } - - public AddressFormat(String format) { - this.format = format; - } - - private static String replace(String s, String key, String value) { - if (value != null) { - s = s.replace(key, value); - } else { - s = s.replaceAll("[, ]*" + key, ""); - } - return s; - } - - @Override - public StringBuffer format(Object o, StringBuffer stringBuffer, FieldPosition fieldPosition) { - Address address = (Address) o; - String result = format; - - result = replace(result, "%p", address.getPostcode()); - result = replace(result, "%c", address.getCountry()); - result = replace(result, "%s", address.getState()); - result = replace(result, "%d", address.getDistrict()); - result = replace(result, "%t", address.getSettlement()); - result = replace(result, "%u", address.getSuburb()); - result = replace(result, "%r", address.getStreet()); - result = replace(result, "%h", address.getHouse()); - - result = result.replaceAll("^[, ]*", ""); - - return stringBuffer.append(result); - } - - @Override - public Address parseObject(String s, ParsePosition parsePosition) { - throw new UnsupportedOperationException(); - } - -} diff --git a/src/org/traccar/geocoder/BingMapsGeocoder.java b/src/org/traccar/geocoder/BingMapsGeocoder.java deleted file mode 100644 index a9b36219a..000000000 --- a/src/org/traccar/geocoder/BingMapsGeocoder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import javax.json.JsonArray; -import javax.json.JsonObject; - -public class BingMapsGeocoder extends JsonGeocoder { - - public BingMapsGeocoder(String url, String key, int cacheSize) { - super(url + "/Locations/%f,%f?key=" + key + "&include=ciso2", cacheSize); - } - - @Override - public Address parseAddress(JsonObject json) { - JsonArray result = json.getJsonArray("resourceSets"); - if (result != null) { - JsonObject location = - result.getJsonObject(0).getJsonArray("resources").getJsonObject(0).getJsonObject("address"); - if (location != null) { - Address address = new Address(); - if (location.containsKey("addressLine")) { - address.setStreet(location.getString("addressLine")); - } - if (location.containsKey("locality")) { - address.setSettlement(location.getString("locality")); - } - if (location.containsKey("adminDistrict2")) { - address.setDistrict(location.getString("adminDistrict2")); - } - if (location.containsKey("adminDistrict")) { - address.setState(location.getString("adminDistrict")); - } - if (location.containsKey("countryRegionIso2")) { - address.setCountry(location.getString("countryRegionIso2").toUpperCase()); - } - if (location.containsKey("postalCode")) { - address.setPostcode(location.getString("postalCode")); - } - return address; - } - } - return null; - } - -} diff --git a/src/org/traccar/geocoder/FactualGeocoder.java b/src/org/traccar/geocoder/FactualGeocoder.java deleted file mode 100644 index 0c76e4625..000000000 --- a/src/org/traccar/geocoder/FactualGeocoder.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import javax.json.JsonObject; - -public class FactualGeocoder extends JsonGeocoder { - - public FactualGeocoder(String url, String key, int cacheSize) { - super(url + "?latitude=%f&longitude=%f&KEY=" + key, cacheSize); - } - - @Override - public Address parseAddress(JsonObject json) { - JsonObject result = json.getJsonObject("response").getJsonObject("data"); - if (result != null) { - Address address = new Address(); - if (result.getJsonObject("street_number") != null) { - address.setHouse(result.getJsonObject("street_number").getString("name")); - } - if (result.getJsonObject("street_name") != null) { - address.setStreet(result.getJsonObject("street_name").getString("name")); - } - if (result.getJsonObject("locality") != null) { - address.setSettlement(result.getJsonObject("locality").getString("name")); - } - if (result.getJsonObject("county") != null) { - address.setDistrict(result.getJsonObject("county").getString("name")); - } - if (result.getJsonObject("region") != null) { - address.setState(result.getJsonObject("region").getString("name")); - } - if (result.getJsonObject("country") != null) { - address.setCountry(result.getJsonObject("country").getString("name")); - } - if (result.getJsonObject("postcode") != null) { - address.setPostcode(result.getJsonObject("postcode").getString("name")); - } - return address; - } - return null; - } - -} diff --git a/src/org/traccar/geocoder/GeocodeFarmGeocoder.java b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java deleted file mode 100644 index 73ff85aa4..000000000 --- a/src/org/traccar/geocoder/GeocodeFarmGeocoder.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import javax.json.JsonObject; - -public class GeocodeFarmGeocoder extends JsonGeocoder { - - private static String formatUrl(String key, String language) { - String url = "https://www.geocode.farm/v3/json/reverse/"; - url += "?lat=%f&lon=%f&country=us&count=1"; - if (key != null) { - url += "&key=" + key; - } - if (language != null) { - url += "&lang=" + language; - } - return url; - } - public GeocodeFarmGeocoder(String key, String language, int cacheSize) { - super(formatUrl(key, language), cacheSize); - } - - @Override - public Address parseAddress(JsonObject json) { - Address address = new Address(); - - JsonObject result = json - .getJsonObject("geocoding_results") - .getJsonArray("RESULTS") - .getJsonObject(0) - .getJsonObject("ADDRESS"); - - if (result.containsKey("street_number")) { - address.setStreet(result.getString("street_number")); - } - if (result.containsKey("street_name")) { - address.setStreet(result.getString("street_name")); - } - if (result.containsKey("locality")) { - address.setSettlement(result.getString("locality")); - } - if (result.containsKey("admin_1")) { - address.setState(result.getString("admin_1")); - } - if (result.containsKey("country")) { - address.setCountry(result.getString("country")); - } - - return address; - } - -} diff --git a/src/org/traccar/geocoder/Geocoder.java b/src/org/traccar/geocoder/Geocoder.java deleted file mode 100644 index 3ce3fb67f..000000000 --- a/src/org/traccar/geocoder/Geocoder.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012 - 2013 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -public interface Geocoder { - - interface ReverseGeocoderCallback { - - void onSuccess(String address); - - void onFailure(Throwable e); - - } - - void getAddress(AddressFormat format, double latitude, double longitude, ReverseGeocoderCallback callback); - -} diff --git a/src/org/traccar/geocoder/GeocoderException.java b/src/org/traccar/geocoder/GeocoderException.java deleted file mode 100644 index 608916641..000000000 --- a/src/org/traccar/geocoder/GeocoderException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -public class GeocoderException extends RuntimeException { - - public GeocoderException(String message) { - super(message); - } - -} diff --git a/src/org/traccar/geocoder/GisgraphyGeocoder.java b/src/org/traccar/geocoder/GisgraphyGeocoder.java deleted file mode 100644 index 1432166e9..000000000 --- a/src/org/traccar/geocoder/GisgraphyGeocoder.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015 - 2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import javax.json.JsonObject; - -public class GisgraphyGeocoder extends JsonGeocoder { - - public GisgraphyGeocoder() { - this("http://services.gisgraphy.com/reversegeocoding/search", 0); - } - - public GisgraphyGeocoder(String url, int cacheSize) { - super(url + "?format=json&lat=%f&lng=%f&from=1&to=1", cacheSize); - } - - @Override - public Address parseAddress(JsonObject json) { - Address address = new Address(); - - JsonObject result = json.getJsonArray("result").getJsonObject(0); - - if (result.containsKey("streetName")) { - address.setStreet(result.getString("streetName")); - } - if (result.containsKey("city")) { - address.setSettlement(result.getString("city")); - } - if (result.containsKey("state")) { - address.setState(result.getString("state")); - } - if (result.containsKey("countryCode")) { - address.setCountry(result.getString("countryCode")); - } - - return address; - } - -} diff --git a/src/org/traccar/geocoder/GoogleGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java deleted file mode 100644 index b38870c8f..000000000 --- a/src/org/traccar/geocoder/GoogleGeocoder.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2012 - 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonString; - -public class GoogleGeocoder extends JsonGeocoder { - - private static String formatUrl(String key, String language) { - String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f"; - if (key != null) { - url += "&key=" + key; - } - if (language != null) { - url += "&language=" + language; - } - return url; - } - - public GoogleGeocoder(String key, String language, int cacheSize) { - super(formatUrl(key, language), cacheSize); - } - - @Override - public Address parseAddress(JsonObject json) { - JsonArray results = json.getJsonArray("results"); - - if (!results.isEmpty()) { - Address address = new Address(); - - JsonObject result = (JsonObject) results.get(0); - JsonArray components = result.getJsonArray("address_components"); - - for (JsonObject component : components.getValuesAs(JsonObject.class)) { - - String value = component.getString("short_name"); - - typesLoop: for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) { - - switch (type.getString()) { - case "street_number": - address.setHouse(value); - break typesLoop; - case "route": - address.setStreet(value); - break typesLoop; - case "locality": - address.setSettlement(value); - break typesLoop; - case "administrative_area_level_2": - address.setDistrict(value); - break typesLoop; - case "administrative_area_level_1": - address.setState(value); - break typesLoop; - case "country": - address.setCountry(value); - break typesLoop; - case "postal_code": - address.setPostcode(value); - break typesLoop; - default: - break; - } - } - } - - return address; - } - - return null; - } - -} diff --git a/src/org/traccar/geocoder/JsonGeocoder.java b/src/org/traccar/geocoder/JsonGeocoder.java deleted file mode 100644 index 6d1380729..000000000 --- a/src/org/traccar/geocoder/JsonGeocoder.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import com.ning.http.client.AsyncCompletionHandler; -import com.ning.http.client.Response; -import org.traccar.Context; - -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; -import java.util.AbstractMap; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -public abstract class JsonGeocoder implements Geocoder { - - private final String url; - - private Map<Map.Entry<Double, Double>, String> cache; - - public JsonGeocoder(String url, final int cacheSize) { - this.url = url; - if (cacheSize > 0) { - this.cache = Collections.synchronizedMap(new LinkedHashMap<Map.Entry<Double, Double>, String>() { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > cacheSize; - } - }); - } - } - - @Override - public void getAddress( - final AddressFormat format, final double latitude, - final double longitude, final ReverseGeocoderCallback callback) { - - if (cache != null) { - String cachedAddress = cache.get(new AbstractMap.SimpleImmutableEntry<>(latitude, longitude)); - if (cachedAddress != null) { - callback.onSuccess(cachedAddress); - return; - } - } - - Context.getAsyncHttpClient().prepareGet(String.format(url, latitude, longitude)) - .execute(new AsyncCompletionHandler() { - @Override - public Object onCompleted(Response response) throws Exception { - try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) { - Address address = parseAddress(reader.readObject()); - if (address != null) { - String formattedAddress = format.format(address); - if (cache != null) { - cache.put(new AbstractMap.SimpleImmutableEntry<>(latitude, longitude), formattedAddress); - } - callback.onSuccess(formattedAddress); - } else { - callback.onFailure(new GeocoderException("Empty address")); - } - } - return null; - } - - @Override - public void onThrowable(Throwable t) { - callback.onFailure(t); - } - }); - } - - public abstract Address parseAddress(JsonObject json); - -} diff --git a/src/org/traccar/geocoder/MapQuestGeocoder.java b/src/org/traccar/geocoder/MapQuestGeocoder.java deleted file mode 100644 index 7d7217e91..000000000 --- a/src/org/traccar/geocoder/MapQuestGeocoder.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import javax.json.JsonArray; -import javax.json.JsonObject; - -public class MapQuestGeocoder extends JsonGeocoder { - - public MapQuestGeocoder(String url, String key, int cacheSize) { - super(url + "?key=" + key + "&location=%f,%f", cacheSize); - } - - @Override - public Address parseAddress(JsonObject json) { - JsonArray result = json.getJsonArray("results"); - if (result != null) { - JsonArray locations = result.getJsonObject(0).getJsonArray("locations"); - if (locations != null) { - JsonObject location = locations.getJsonObject(0); - - Address address = new Address(); - - if (location.containsKey("street")) { - address.setStreet(location.getString("street")); - } - if (location.containsKey("adminArea5")) { - address.setSettlement(location.getString("adminArea5")); - } - if (location.containsKey("adminArea4")) { - address.setDistrict(location.getString("adminArea4")); - } - if (location.containsKey("adminArea3")) { - address.setState(location.getString("adminArea3")); - } - if (location.containsKey("adminArea1")) { - address.setCountry(location.getString("adminArea1").toUpperCase()); - } - if (location.containsKey("postalCode")) { - address.setPostcode(location.getString("postalCode")); - } - - return address; - } - } - return null; - } - -} diff --git a/src/org/traccar/geocoder/NominatimGeocoder.java b/src/org/traccar/geocoder/NominatimGeocoder.java deleted file mode 100644 index 051727e93..000000000 --- a/src/org/traccar/geocoder/NominatimGeocoder.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2014 - 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import javax.json.JsonObject; - -public class NominatimGeocoder extends JsonGeocoder { - - private static String formatUrl(String url, String key, String language) { - if (url == null) { - url = "http://nominatim.openstreetmap.org/reverse"; - } - url += "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1"; - if (key != null) { - url += "&key=" + key; - } - if (language != null) { - url += "&accept-language=" + language; - } - return url; - } - - public NominatimGeocoder(String url, String key, String language, int cacheSize) { - super(formatUrl(url, key, language), cacheSize); - } - - @Override - public Address parseAddress(JsonObject json) { - JsonObject result = json.getJsonObject("address"); - - if (result != null) { - Address address = new Address(); - - if (result.containsKey("house_number")) { - address.setHouse(result.getString("house_number")); - } - if (result.containsKey("road")) { - address.setStreet(result.getString("road")); - } - if (result.containsKey("suburb")) { - address.setSuburb(result.getString("suburb")); - } - - if (result.containsKey("village")) { - address.setSettlement(result.getString("village")); - } else if (result.containsKey("town")) { - address.setSettlement(result.getString("town")); - } else if (result.containsKey("city")) { - address.setSettlement(result.getString("city")); - } - - if (result.containsKey("state_district")) { - address.setDistrict(result.getString("state_district")); - } else if (result.containsKey("region")) { - address.setDistrict(result.getString("region")); - } - - if (result.containsKey("state")) { - address.setState(result.getString("state")); - } - if (result.containsKey("country_code")) { - address.setCountry(result.getString("country_code").toUpperCase()); - } - if (result.containsKey("postcode")) { - address.setPostcode(result.getString("postcode")); - } - - return address; - } - - return null; - } - -} diff --git a/src/org/traccar/geocoder/OpenCageGeocoder.java b/src/org/traccar/geocoder/OpenCageGeocoder.java deleted file mode 100644 index 9fa56a4a3..000000000 --- a/src/org/traccar/geocoder/OpenCageGeocoder.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com) - * Copyright 2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import javax.json.JsonArray; -import javax.json.JsonObject; - -public class OpenCageGeocoder extends JsonGeocoder { - - public OpenCageGeocoder(String url, String key, int cacheSize) { - super(url + "/json?q=%f,%f&key=" + key, cacheSize); - } - - @Override - public Address parseAddress(JsonObject json) { - JsonArray result = json.getJsonArray("results"); - if (result != null) { - JsonObject location = result.getJsonObject(0).getJsonObject("components"); - if (location != null) { - Address address = new Address(); - - if (location.containsKey("building")) { - address.setHouse(location.getString("building")); - } - if (location.containsKey("house_number")) { - address.setHouse(location.getString("house_number")); - } - if (location.containsKey("road")) { - address.setStreet(location.getString("road")); - } - if (location.containsKey("suburb")) { - address.setSuburb(location.getString("suburb")); - } - if (location.containsKey("city")) { - address.setSettlement(location.getString("city")); - } - if (location.containsKey("city_district")) { - address.setSettlement(location.getString("city_district")); - } - if (location.containsKey("county")) { - address.setDistrict(location.getString("county")); - } - if (location.containsKey("state")) { - address.setState(location.getString("state")); - } - if (location.containsKey("country_code")) { - address.setCountry(location.getString("country_code").toUpperCase()); - } - if (location.containsKey("postcode")) { - address.setPostcode(location.getString("postcode")); - } - - return address; - } - } - return null; - } - -} |