use of org.mapton.api.MBookmark in project mapton by trixon.
the class DuckDuckGo method getResults.
private ArrayList<MBookmark> getResults() {
ArrayList<MBookmark> bookmarks = new ArrayList<>();
GeonamesManager.getInstance().getGeonames().stream().forEachOrdered((g) -> {
MBookmark b = new MBookmark();
b.setName(g.getName());
b.setCategory(g.getCountryCode());
b.setLatitude(g.getLatitude());
b.setLongitude(g.getLongitude());
b.setZoom(0.5);
bookmarks.add(b);
});
return bookmarks;
}
use of org.mapton.api.MBookmark in project mapton by trixon.
the class DuckDuckGo method getUrl.
@Override
public String getUrl() {
MLatLon hereLatLon = new MLatLon(getLongitude(), getLatitude());
MBookmark nearest = new MBookmark();
double dist = Double.MAX_VALUE;
for (MBookmark bookmark : getResults()) {
MLatLon bookmarkLatLon = new MLatLon(bookmark.getLongitude(), bookmark.getLatitude());
double newDistance = hereLatLon.distance(bookmarkLatLon);
if (newDistance < dist) {
dist = newDistance;
nearest = bookmark;
if (dist < 1000) {
break;
}
}
}
try {
return String.format("https://duckduckgo.com/?q=%s", URLEncoder.encode(nearest.getName(), "UTF-8"));
} catch (UnsupportedEncodingException ex) {
return null;
}
}
Aggregations