use of org.opennms.features.poller.remote.gwt.server.geocoding.GeocoderException in project opennms by OpenNMS.
the class DefaultLocationDataService method getLatLng.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public GWTLatLng getLatLng(final OnmsMonitoringLocation def, boolean x) {
GWTLatLng latLng = null;
final String coordinateMatchString = "^\\s*[\\-\\d\\.]+\\s*,\\s*[\\-\\d\\.]+\\s*$";
// first, see if we already have coordinates
if (def.getLatitude() != null && def.getLongitude() != null) {
latLng = new GWTLatLng(def.getLatitude(), def.getLongitude());
}
// if not, see if geolocation is coordinates
if (latLng == null) {
LOG.debug("using geolocation: {}", def.getGeolocation());
if (def.getGeolocation() != null && def.getGeolocation().matches(coordinateMatchString)) {
final String[] coordinates = def.getGeolocation().split(",");
latLng = new GWTLatLng(Double.valueOf(coordinates[0]), Double.valueOf(coordinates[1]));
}
}
// otherwise, try to geocode it
if (latLng == null && def.getGeolocation() != null && !def.getGeolocation().equals("")) {
try {
latLng = m_geocoder.geocode(def.getGeolocation());
LOG.debug("got coordinates {} for geolocation {}", latLng.getCoordinates(), def.getGeolocation());
} catch (GeocoderException e) {
LOG.warn("unable to geocode {}", def.getGeolocation(), e);
}
}
return latLng;
}
Aggregations