Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate geoCoder() endpoint to Retrofit
- Loading branch information
1 parent
518fabf
commit d18cb8f
Showing
12 changed files
with
218 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<lint> | ||
<issue id="InvalidPackage"> | ||
<!-- https://github.com/FasterXML/jackson-databind/issues/1192 --> | ||
<ignore regexp=".*jackson.*" /> | ||
<!-- https://github.com/codepath/android_guides/wiki/Consuming-APIs-with-Retrofit#issues --> | ||
<ignore regexp=".*okio.*" /> | ||
<ignore regexp=".*retrofit.*" /> | ||
<!-- http://sourceforge.net/p/simple/mailman/simple-support/thread/339270128E13BE47A6B10EED7367E7852BC2A912@MERCMBX18D.na.SAS.com/ --> | ||
<ignore regexp=".*simple-xml.*" /> | ||
</issue> | ||
</lint> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 28 additions & 120 deletions
148
libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/GeoPlaces.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,43 @@ | ||
package net.cyclestreets.api; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
|
||
import org.osmdroid.util.BoundingBoxE6; | ||
import org.osmdroid.util.GeoPoint; | ||
import org.xml.sax.Attributes; | ||
import org.xml.sax.ContentHandler; | ||
|
||
import android.sax.Element; | ||
import android.sax.EndElementListener; | ||
import android.sax.EndTextElementListener; | ||
import android.sax.RootElement; | ||
import android.sax.StartElementListener; | ||
|
||
public class GeoPlaces implements Iterable<GeoPlace> | ||
{ | ||
private List<GeoPlace> places_; | ||
|
||
private GeoPlaces() | ||
{ | ||
places_ = new ArrayList<>(); | ||
} // GeoPlaces | ||
|
||
private void add(final GeoPlace place) { places_.add(place); } | ||
|
||
private List<GeoPlace> places = new ArrayList<>(); | ||
|
||
public GeoPlaces(Collection<GeoPlace> places) { | ||
this.places.addAll(places); | ||
} | ||
|
||
private GeoPlaces() {} | ||
|
||
@Override | ||
public Iterator<GeoPlace> iterator() { return places_.iterator(); } | ||
public boolean isEmpty() { return places_.isEmpty(); } | ||
public int size() { return places_.size(); } | ||
public GeoPlace get(int index) { return places_.get(index); } | ||
public List<GeoPlace> asList() { return places_; } | ||
public Iterator<GeoPlace> iterator() { return places.iterator(); } | ||
|
||
public boolean isEmpty() { return places.isEmpty(); } | ||
|
||
public int size() { return places.size(); } | ||
public GeoPlace get(int index) { return places.get(index); } | ||
|
||
public List<GeoPlace> asList() { return places; } | ||
|
||
static public GeoPlaces EMPTY = new GeoPlaces(); | ||
|
||
/////////////////////////////////////////////// | ||
static public GeoPlaces search(final String searchTerm, | ||
final BoundingBoxE6 bounds) | ||
throws Exception | ||
{ | ||
return search(searchTerm, | ||
bounds.getLatNorthE6() / 1E6, | ||
bounds.getLatSouthE6() / 1E6, | ||
bounds.getLonEastE6() / 1E6, | ||
bounds.getLonWestE6() / 1E6); | ||
} // search | ||
|
||
static public GeoPlaces search(final String searchTerm, | ||
double n, | ||
double s, | ||
double e, | ||
double w) | ||
throws Exception | ||
{ | ||
return ApiClient.geoCoder(searchTerm, n, s, e, w); | ||
} // search | ||
|
||
//////////////////////////////////////////////////// | ||
static public Factory<GeoPlaces> factory() { | ||
return new GeoPlacesFactory(); | ||
} // factory | ||
|
||
static private class GeoPlacesFactory extends Factory.XmlReader<GeoPlaces> | ||
{ | ||
private GeoPlaces places_; | ||
private String name_; | ||
private String near_; | ||
private String lat_; | ||
private String lon_; | ||
|
||
public GeoPlacesFactory() | ||
{ | ||
} // GeoPlacesFactory | ||
|
||
@Override | ||
protected ContentHandler contentHandler() | ||
{ | ||
places_ = new GeoPlaces(); | ||
|
||
final RootElement root = new RootElement("sayt"); | ||
final Element item = root.getChild("results").getChild("result"); | ||
item.setStartElementListener(new StartElementListener() { | ||
@Override | ||
public void start(Attributes attributes) | ||
{ | ||
name_ = null; | ||
near_ = null; | ||
lat_ = null; | ||
lon_ = null; | ||
} | ||
}); | ||
item.setEndElementListener(new EndElementListener(){ | ||
public void end() { | ||
final GeoPoint coord = new GeoPoint(Double.parseDouble(lat_), | ||
Double.parseDouble(lon_)); | ||
places_.add(new GeoPlace(coord, name_, near_)); | ||
} | ||
}); | ||
item.getChild("name").setEndTextElementListener(new EndTextElementListener(){ | ||
public void end(String body) { | ||
name_ = body; | ||
} | ||
}); | ||
item.getChild("near").setEndTextElementListener(new EndTextElementListener(){ | ||
public void end(String body) { | ||
near_ = body; | ||
} | ||
}); | ||
item.getChild("latitude").setEndTextElementListener(new EndTextElementListener(){ | ||
public void end(String body) { | ||
lat_ = body; | ||
} | ||
}); | ||
item.getChild("longitude").setEndTextElementListener(new EndTextElementListener(){ | ||
public void end(String body) { | ||
lon_ = body; | ||
} | ||
}); | ||
|
||
return root.getContentHandler(); | ||
} // contentHandler | ||
|
||
@Override | ||
protected GeoPlaces get() | ||
{ | ||
return places_; | ||
} // get | ||
} // POICategoriesFactory | ||
} // class GeoPlaces | ||
throws IOException { | ||
return ApiClient.geoCoder(searchTerm, | ||
bounds.getLatNorthE6() / 1E6, | ||
bounds.getLatSouthE6() / 1E6, | ||
bounds.getLonEastE6() / 1E6, | ||
bounds.getLonWestE6() / 1E6); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 12 additions & 1 deletion
13
libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/V1Api.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
package net.cyclestreets.api.client; | ||
|
||
import net.cyclestreets.api.client.dto.GeoPlacesDto; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Query; | ||
|
||
public interface V1Api { | ||
|
||
// Pending | ||
@GET("/api/geocoder.xml?countrycodes=gb,ie") | ||
Call<GeoPlacesDto> geoCoder(@Query("street") String search, | ||
@Query("n") double n, | ||
@Query("s") double s, | ||
@Query("e") double e, | ||
@Query("w") double w); | ||
} |
26 changes: 26 additions & 0 deletions
26
libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/dto/GeoPlaceDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.cyclestreets.api.client.dto; | ||
|
||
import net.cyclestreets.api.GeoPlace; | ||
|
||
import org.osmdroid.util.GeoPoint; | ||
import org.simpleframework.xml.Element; | ||
import org.simpleframework.xml.Root; | ||
|
||
@Root(name = "result") | ||
public class GeoPlaceDto { | ||
|
||
@Element | ||
private String name; | ||
@Element | ||
private String near; | ||
@Element | ||
private String type; | ||
@Element | ||
private double longitude; | ||
@Element | ||
private double latitude; | ||
|
||
public GeoPlace toGeoPlace() { | ||
return new GeoPlace(new GeoPoint(latitude, longitude), name, near); | ||
} | ||
} |
Oops, something went wrong.