private Geonames getGeonamesFor(String uri, double longitude, double latitude) throws IOException {
return getGeonamesFor(uri + "?lat=" + latitude + "&lng=" + longitude);
}
private String getNearByFor(String uri, double longitude, double latitude) throws IOException {
Geonames geonames = getGeonamesFor(uri, longitude, latitude);
if (geonames == null || geonames.getGeoname() == null)
return null;
if (geonames.getStatus() != null)
throw new IOException(geonames.getStatus().getMessage());
List<String> result = new ArrayList<String>();
for (Geonames.Geoname geoname : geonames.getGeoname()) {
result.add(geoname.getName());
}
return result.size() > 0 ? result.get(0) : null;
}