use of org.opentripplanner.geocoder.GeocoderResult 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.GeocoderResult 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