use of com.graphhopper.api.model.GHGeocodingRequest in project graphhopper by graphhopper.
the class GraphHopperGeocoding method geocode.
/**
* Perform a geocoding request. Both forward and revers are possible, just configure the <code>request</code>
* accordingly.
*
* @param request the request to send to the API
* @return found results for your request
*/
public GHGeocodingResponse geocode(GHGeocodingRequest request) {
String url = buildUrl(request);
try {
Request okRequest = new Request.Builder().url(url).build();
ResponseBody rspBody = getClientForRequest(request).newCall(okRequest).execute().body();
return objectMapper.readValue(rspBody.bytes(), GHGeocodingResponse.class);
} catch (Exception ex) {
throw new RuntimeException("Problem performing geocoding for " + url + ": " + ex.getMessage(), ex);
}
}
use of com.graphhopper.api.model.GHGeocodingRequest in project graphhopper by graphhopper.
the class GraphHopperGeocodingIT method testReverseGeocoding.
@Test
public void testReverseGeocoding() {
GHGeocodingResponse response = geocoding.geocode(new GHGeocodingRequest(52.5170365, 13.3888599, "en", 5));
assertEquals(5, response.getHits().size());
GHGeocodingEntry entry = response.getHits().get(0);
assertTrue(entry.getName().contains("Berlin"));
assertEquals("place", entry.getOsmKey());
assertEquals(0, entry.getExtent().length);
}
use of com.graphhopper.api.model.GHGeocodingRequest in project graphhopper by graphhopper.
the class GraphHopperGeocodingIT method testExtent.
@Test
public void testExtent() {
GHGeocodingResponse response = geocoding.geocode(new GHGeocodingRequest("new york", "en", 7));
BBox extent = response.getHits().get(0).getExtendBBox();
assertTrue(extent.isValid());
assertTrue(extent.minLon < -79);
assertTrue(extent.maxLon > -72);
assertTrue(extent.minLat < 40.5);
assertTrue(extent.maxLat > 45);
}
use of com.graphhopper.api.model.GHGeocodingRequest in project graphhopper by graphhopper.
the class GraphHopperGeocodingIT method testForwardGeocoding.
@Test
public void testForwardGeocoding() {
GHGeocodingResponse response = geocoding.geocode(new GHGeocodingRequest("Berlin", "en", 7));
assertEquals(7, response.getHits().size());
assertTrue(response.getHits().get(0).getName().contains("Berlin"));
}
use of com.graphhopper.api.model.GHGeocodingRequest in project graphhopper by graphhopper.
the class GraphHopperGeocodingIT method testForwardGeocodingNominatim.
@Test
public void testForwardGeocodingNominatim() {
GHGeocodingResponse response = geocoding.geocode(new GHGeocodingRequest(false, null, "Berlin", "en", 5, "nominatim", 5000));
assertEquals(5, response.getHits().size());
assertTrue(response.getHits().get(0).getName().contains("Berlin"));
}
Aggregations