Kenin
Kenin

Reputation: 420

How do I check if location is on the polyline (Here maps)?

I search a method to find if my current location is on the path define by aPolyline.

In google maps a function exist isLocationOnEdge, but I cannot find a similar function in Here maps API.

Upvotes: 1

Views: 750

Answers (1)

user3505695
user3505695

Reputation:

This could be achieved using an approach an below

//global variable
var polyline;
polyline = new H.map.Polyline(strip);
map.addObject(polyline);

function liesOnPolyline(coords){
 // get objects at the coordinates (pixel coordinates, can be converted from lat, lon using map.geoToScreen )
 var objects = map.getObjectsAt(coords.x, coords.y);

 // iterate through the array to check if polyline can be retrieved here
 var withinPolyline = false;
 for (var object in objects) {
     if(objects[object] === polyline){
       withinPolyline = true;
       break;
    }
 }
 console.log("lies within Polyline"+withinPolyline );
}

Upvotes: 1

Related Questions