Search code examples
androidopenstreetmapkmlosmdroid

How to check distance between current position and KML points using OSMDroid?


So, in my project I need to check, every minute, if a user is in a given distance radius of a specified KML.

I searched methods from KmlDocument and FolderOverlay, but none of them give me a list of points or anything else to compare with my current location.

Here is how I get my KML and then apply the overlay to the map:

KmlDocument kmlDocument = new KmlDocument();
map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
if (trail.isDownloaded() && UtilsClass.getInstance().isNetworkAvailable(context) && trail.getFileKmlLocalPath() != null && 
!trail.getFileKmlLocalPath().isEmpty()) {
    File kmlFile = new File(trail.getFileKmlLocalPath());
    if (kmlFile.exists()) {
       kmlDocument.parseKMLFile(kmlFile);
    } else {
       kmlDocument.parseKMLUrl(trail.getFileKml()); 
    }
} else {
    kmlDocument.parseKMLUrl(trail.getFileKml());
}

FolderOverlay kmOverlay = (FolderOverlay) 
kmlDocument.mKmlRoot.buildOverlay(map, null, null, kmlDocument);
map.getOverlays().add(kmOverlay);

Is there a way to accomplish what I want/need?

Thanks in advance


Solution

  • The list of points for each KmlPlacemark (Point, LineString, and Polygon) are in KmlPlacemark.mGeometry.mCoordinates