use of org.opentripplanner.geocoder.GeocoderResults in project OpenTripPlanner by opentripplanner.
the class GoogleGeocoder method geocode.
@Override
public GeocoderResults geocode(String address, Envelope bbox) {
String content = null;
try {
// make json request
URL googleGeocoderUrl = getGoogleGeocoderUrl(address);
URLConnection conn = googleGeocoderUrl.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
StringBuilder sb = new StringBuilder(128);
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
reader.close();
content = sb.toString();
} catch (IOException e) {
LOG.error("Error parsing Google geocoder response", e);
return noGeocoderResult("Error parsing geocoder response");
}
GoogleGeocoderResults googleGeocoderResults = googleJsonDeserializer.parseResults(content);
List<GoogleGeocoderResult> googleResults = googleGeocoderResults.getResults();
List<GeocoderResult> geocoderResults = new ArrayList<GeocoderResult>();
for (GoogleGeocoderResult googleGeocoderResult : googleResults) {
Geometry geometry = googleGeocoderResult.getGeometry();
Location location = geometry.getLocation();
Double lat = location.getLat();
Double lng = location.getLng();
String formattedAddress = googleGeocoderResult.getFormatted_address();
GeocoderResult geocoderResult = new GeocoderResult(lat, lng, formattedAddress);
geocoderResults.add(geocoderResult);
}
return new GeocoderResults(geocoderResults);
}
use of org.opentripplanner.geocoder.GeocoderResults in project OpenTripPlanner by opentripplanner.
the class GeocoderGeoZoneCropper method geocode.
@Override
public GeocoderResults geocode(String address, Envelope bbox) {
GeocoderResults retval = decorated.geocode(address, bbox);
if (retval.getResults() != null) {
List<GeocoderResult> results = new ArrayList<GeocoderResult>(retval.getCount());
for (GeocoderResult result : retval.getResults()) {
if (result.getLat() > minLat && result.getLng() > minLon && result.getLat() < maxLat && result.getLng() < maxLon)
results.add(result);
}
retval.setResults(results);
}
return retval;
}
use of org.opentripplanner.geocoder.GeocoderResults in project OpenTripPlanner by opentripplanner.
the class NominatimGeocoder method geocode.
@Override
public GeocoderResults geocode(String address, Envelope bbox) {
String content = null;
try {
// make json request
URL nominatimGeocoderUrl = getNominatimGeocoderUrl(address, bbox);
URLConnection conn = nominatimGeocoderUrl.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
StringBuilder sb = new StringBuilder(128);
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
reader.close();
content = sb.toString();
} catch (IOException e) {
LOG.error("Error parsing nominatim geocoder response", e);
return noGeocoderResult("Error parsing geocoder response");
}
List<NominatimGeocoderResult> nominatimResults = nominatimJsonDeserializer.parseResults(content);
List<GeocoderResult> geocoderResults = new ArrayList<GeocoderResult>();
for (NominatimGeocoderResult nominatimGeocoderResult : nominatimResults) {
Double lat = nominatimGeocoderResult.getLatDouble();
Double lng = nominatimGeocoderResult.getLngDouble();
String displayName = nominatimGeocoderResult.getDisplay_name();
GeocoderResult geocoderResult = new GeocoderResult(lat, lng, displayName);
geocoderResults.add(geocoderResult);
}
return new GeocoderResults(geocoderResults);
}
Aggregations