conn.setRequestProperty("User-Agent", USER_AGENT);
return conn.getInputStream();
}
private GetLocationResult getLocationFromElement(Element locationElement) {
GetLocationResult location = new GetLocationResult();
List<String> canonical = new ArrayList<String>();
canonicalAdd(canonical, locationElement, "line4");
canonicalAdd(canonical, locationElement, "line3");
canonicalAdd(canonical, locationElement, "line2");
canonicalAdd(canonical, locationElement, "line1");
if (0 == canonical.size()) {
canonicalAdd(canonical, locationElement, "level5");
canonicalAdd(canonical, locationElement, "level4");
canonicalAdd(canonical, locationElement, "level3");
canonicalAdd(canonical, locationElement, "level2");
canonicalAdd(canonical, locationElement, "level1");
canonicalAdd(canonical, locationElement, "level0");
}
location.setCanonicalStrings(canonical);
Element area = locationElement.getChild("boundingbox");
if (null != area) {
double north = Double.parseDouble(area.getChildText("north"));
double south = Double.parseDouble(area.getChildText("south"));
double east = Double.parseDouble(area.getChildText("east"));
double west = Double.parseDouble(area.getChildText("west"));
if (Math.abs(north - south) > DELTA || Math.abs(east - west) > DELTA) {
// return point when bbox is a point
Bbox bbox = new Bbox(west, south, east - west, north - south);
location.setEnvelope(dtoConverterService.toInternal(bbox));
}
}
location.setCoordinate(new Coordinate(Double.parseDouble(locationElement.getChildText("longitude")),
Double.parseDouble(locationElement.getChildText("latitude"))));
return location;
}