aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/geocode/BingMapsReverseGeocoder.java4
-rw-r--r--src/org/traccar/geocode/FactualReverseGeocoder.java4
-rw-r--r--src/org/traccar/geocode/MapQuestReverseGeocoder.java4
-rw-r--r--src/org/traccar/geocode/OpenCageReverseGeocoder.java14
-rw-r--r--test/org/traccar/geocode/ReverseGeocoderTest.java48
5 files changed, 49 insertions, 25 deletions
diff --git a/src/org/traccar/geocode/BingMapsReverseGeocoder.java b/src/org/traccar/geocode/BingMapsReverseGeocoder.java
index a5ebbd420..69148875a 100644
--- a/src/org/traccar/geocode/BingMapsReverseGeocoder.java
+++ b/src/org/traccar/geocode/BingMapsReverseGeocoder.java
@@ -20,10 +20,6 @@ import javax.json.JsonObject;
public class BingMapsReverseGeocoder extends JsonReverseGeocoder {
- public BingMapsReverseGeocoder() {
- this("http://dev.virtualearth.net/REST/v1", "ABCDE", 0);
- }
-
public BingMapsReverseGeocoder(String url, String key, int cacheSize) {
super(url + "/Locations/%f,%f?key=" + key + "&include=ciso2", cacheSize);
}
diff --git a/src/org/traccar/geocode/FactualReverseGeocoder.java b/src/org/traccar/geocode/FactualReverseGeocoder.java
index 6e5a48423..15211f74a 100644
--- a/src/org/traccar/geocode/FactualReverseGeocoder.java
+++ b/src/org/traccar/geocode/FactualReverseGeocoder.java
@@ -19,10 +19,6 @@ import javax.json.JsonObject;
public class FactualReverseGeocoder extends JsonReverseGeocoder {
- public FactualReverseGeocoder() {
- this("https://api.factual.com/geotag", "ABCDE", 0);
- }
-
public FactualReverseGeocoder(String url, String key, int cacheSize) {
super(url + "?latitude=%f&longitude=%f&KEY=" + key, cacheSize);
}
diff --git a/src/org/traccar/geocode/MapQuestReverseGeocoder.java b/src/org/traccar/geocode/MapQuestReverseGeocoder.java
index be3f51b04..93edfdd09 100644
--- a/src/org/traccar/geocode/MapQuestReverseGeocoder.java
+++ b/src/org/traccar/geocode/MapQuestReverseGeocoder.java
@@ -20,10 +20,6 @@ import javax.json.JsonObject;
public class MapQuestReverseGeocoder extends JsonReverseGeocoder {
- public MapQuestReverseGeocoder() {
- this("http://www.mapquestapi.com/geocoding/v1/reverse", "ABCDE", 0);
- }
-
public MapQuestReverseGeocoder(String url, String key, int cacheSize) {
super(url + "?key=" + key + "&location=%f,%f", cacheSize);
}
diff --git a/src/org/traccar/geocode/OpenCageReverseGeocoder.java b/src/org/traccar/geocode/OpenCageReverseGeocoder.java
index 3104cb56a..b5b31179e 100644
--- a/src/org/traccar/geocode/OpenCageReverseGeocoder.java
+++ b/src/org/traccar/geocode/OpenCageReverseGeocoder.java
@@ -1,5 +1,6 @@
/*
* Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com)
+ * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +21,6 @@ import javax.json.JsonObject;
public class OpenCageReverseGeocoder extends JsonReverseGeocoder {
- public OpenCageReverseGeocoder() {
- this("https://api.opencagedata.com/geocode/v1", "ABCDE", 0);
- }
-
public OpenCageReverseGeocoder(String url, String key, int cacheSize) {
super(url + "/json?q=%f,%f&key=" + key, cacheSize);
}
@@ -36,12 +33,21 @@ public class OpenCageReverseGeocoder extends JsonReverseGeocoder {
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"));
}
diff --git a/test/org/traccar/geocode/ReverseGeocoderTest.java b/test/org/traccar/geocode/ReverseGeocoderTest.java
index a572b0456..ada0afbbe 100644
--- a/test/org/traccar/geocode/ReverseGeocoderTest.java
+++ b/test/org/traccar/geocode/ReverseGeocoderTest.java
@@ -8,45 +8,75 @@ public class ReverseGeocoderTest {
private boolean enable = false;
@Test
- public void test() {
+ public void test() throws InterruptedException {
if (enable) {
testGoogle();
- testNominatim();
- testGisgraphy();
}
}
- public void testGoogle() {
+ private String address;
+
+ private synchronized String waitAddress() {
+ try {
+ wait(5000);
+ return address;
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private synchronized void setAddress(String address) {
+ this.address = address;
+ notifyAll();
+ }
+
+ public void testGoogle() throws InterruptedException {
ReverseGeocoder reverseGeocoder = new GoogleReverseGeocoder();
reverseGeocoder.getAddress(new AddressFormat(), 37.4217550, -122.0846330, new ReverseGeocoder.ReverseGeocoderCallback() {
@Override
public void onResult(String address) {
- Assert.assertEquals("1600 Amphitheatre Pkwy, Mountain View, CA, US", address);
+ setAddress(address);
}
});
+ Assert.assertEquals("1600 Amphitheatre Pkwy, Mountain View, CA, US", waitAddress());
}
- public void testNominatim() {
+ public void testNominatim() throws InterruptedException {
ReverseGeocoder reverseGeocoder = new NominatimReverseGeocoder();
reverseGeocoder.getAddress(new AddressFormat(), 40.7337807, -73.9974401, new ReverseGeocoder.ReverseGeocoderCallback() {
@Override
public void onResult(String address) {
- Assert.assertEquals("35 West 9th Street, NYC, New York, US", address);
+ setAddress(address);
}
});
+ Assert.assertEquals("35 West 9th Street, NYC, New York, US", waitAddress());
}
- public void testGisgraphy() {
+ public void testGisgraphy() throws InterruptedException {
ReverseGeocoder reverseGeocoder = new GisgraphyReverseGeocoder();
reverseGeocoder.getAddress(new AddressFormat(), 48.8530000, 2.3400000, new ReverseGeocoder.ReverseGeocoderCallback() {
@Override
public void onResult(String address) {
- Assert.assertEquals("Rue du Jardinet, Paris, FR", address);
+ setAddress(address);
+ }
+ });
+ Assert.assertEquals("Rue du Jardinet, Paris, FR", waitAddress());
+ }
+
+ public void testOpenCage() throws InterruptedException {
+ ReverseGeocoder reverseGeocoder = new OpenCageReverseGeocoder(
+ "http://api.opencagedata.com/geocode/v1", "SECRET", 0);
+
+ reverseGeocoder.getAddress(new AddressFormat(), 34.116302, -118.051519, new ReverseGeocoder.ReverseGeocoderCallback() {
+ @Override
+ public void onResult(String address) {
+ setAddress(address);
}
});
+ Assert.assertEquals("Charleston Road, California, US", waitAddress());
}
}