Search in sources :

Example 1 with Geocoder

use of org.opentripplanner.geocoder.Geocoder in project OpenTripPlanner by opentripplanner.

the class GeocoderServerTest method testGeocodeValidAddress.

@Test
public void testGeocodeValidAddress() {
    final double lat = 78.121;
    final double lng = -43.237;
    final String description = "121 elm street";
    geocoderServer.geocoder = new Geocoder() {

        @Override
        public GeocoderResults geocode(String address, Envelope bbox) {
            GeocoderResult result = new GeocoderResult(lat, lng, description);
            return new GeocoderResults(Arrays.asList(result));
        }
    };
    GeocoderResults results = geocoderServer.geocode("121 elm street", null);
    for (GeocoderResult result : results.getResults()) {
        // should only have one result
        assertEquals("description matches", description, result.getDescription());
        assertEquals(lat, result.getLat(), 0.001);
        assertEquals(lng, result.getLng(), 0.001);
    }
}
Also used : GeocoderResults(org.opentripplanner.geocoder.GeocoderResults) Envelope(com.vividsolutions.jts.geom.Envelope) Geocoder(org.opentripplanner.geocoder.Geocoder) GeocoderResult(org.opentripplanner.geocoder.GeocoderResult) Test(org.junit.Test)

Example 2 with Geocoder

use of org.opentripplanner.geocoder.Geocoder in project OpenTripPlanner by opentripplanner.

the class GeocoderServerTest method testGeocodeInvalidAddress.

@Test
public void testGeocodeInvalidAddress() {
    final String error = "uh oh";
    geocoderServer.geocoder = new Geocoder() {

        @Override
        public GeocoderResults geocode(String address, Envelope bbox) {
            return new GeocoderResults(error);
        }
    };
    GeocoderResults result = geocoderServer.geocode("121 elm street", null);
    assertEquals("error returned", error, result.getError());
}
Also used : GeocoderResults(org.opentripplanner.geocoder.GeocoderResults) Envelope(com.vividsolutions.jts.geom.Envelope) Geocoder(org.opentripplanner.geocoder.Geocoder) Test(org.junit.Test)

Aggregations

Envelope (com.vividsolutions.jts.geom.Envelope)2 Test (org.junit.Test)2 Geocoder (org.opentripplanner.geocoder.Geocoder)2 GeocoderResults (org.opentripplanner.geocoder.GeocoderResults)2 GeocoderResult (org.opentripplanner.geocoder.GeocoderResult)1