Search in sources :

Example 11 with MBookmark

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;
}
Also used : MBookmark(org.mapton.api.MBookmark) ArrayList(java.util.ArrayList)

Example 12 with MBookmark

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;
    }
}
Also used : MBookmark(org.mapton.api.MBookmark) MLatLon(org.mapton.api.MLatLon) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

MBookmark (org.mapton.api.MBookmark)12 ArrayList (java.util.ArrayList)5 Point (java.awt.Point)3 GeoPoint (se.trixon.almond.util.io.GeoPoint)3 LatLong (com.dlsc.gmapsfx.javascript.object.LatLong)2 MLatLon (org.mapton.api.MLatLon)2 LatLongBounds (com.dlsc.gmapsfx.javascript.object.LatLongBounds)1 Marker (com.dlsc.gmapsfx.javascript.object.Marker)1 MarkerOptions (com.dlsc.gmapsfx.javascript.object.MarkerOptions)1 GeocoderGeometry (com.dlsc.gmapsfx.service.geocoding.GeocoderGeometry)1 GeocoderStatus (com.dlsc.gmapsfx.service.geocoding.GeocoderStatus)1 GeocodingResult (com.dlsc.gmapsfx.service.geocoding.GeocodingResult)1 GeocodingService (com.dlsc.gmapsfx.service.geocoding.GeocodingService)1 GeocodingServiceCallback (com.dlsc.gmapsfx.service.geocoding.GeocodingServiceCallback)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 Coordinate (com.sothawo.mapjfx.Coordinate)1 MapLabel (com.sothawo.mapjfx.MapLabel)1 Marker (com.sothawo.mapjfx.Marker)1