use of com.google.code.geocoder.GeocoderRequestBuilder in project opennms by OpenNMS.
the class GoogleGeocoderService method getCoordinates.
@Override
public synchronized Coordinates getCoordinates(final String address) throws GeocoderException {
ensureInitialized();
final GeocoderRequest request = new GeocoderRequestBuilder().setAddress(address).setLanguage("en").getGeocoderRequest();
GeocodeResponse response;
try {
response = m_geocoder.geocode(request);
} catch (IOException e) {
// Makes the assumption that IO related exceptions are temporary, which is suitable for most scenarios
throw new TemporaryGeocoderException("Failed to get coordinates for " + address + " using the Google Geocoder.", e);
}
switch(response.getStatus()) {
case OK:
return new GoogleCoordinates(response.getResults().get(0));
case OVER_QUERY_LIMIT:
throw new TemporaryGeocoderException("Failed to get coordinates for " + address + " using the Google Geocoder. You have exceeded the daily usage limit.");
case ERROR:
case INVALID_REQUEST:
case REQUEST_DENIED:
case UNKNOWN_ERROR:
case ZERO_RESULTS:
default:
throw new GeocoderException("Failed to get coordinates for " + address + " using Google Geocoder. Response was: " + response.getStatus().toString());
}
}
Aggregations