Search code examples
yandex-maps

Yandex maps: How to (Can I) set placemarks on the route turns?


I have route from my object to current user position.

ymaps.route([objectPosition, userPosition], {
    mapStateAutoApply: true
}).then(function(route) {
    route.getPaths().options.set({
        balloonContentBodyLayout: ymaps.templateLayoutFactory.createClass('$[properties.humanJamsTime]')
    });

    map.geoObjects.add(route);
});

I want to set placemarks on the route turns. (How) Can I do this with Yandex Maps API? Can I somehow calculate this points and manual set placemarks?

Thank you for advice.


Solution

  • To get information about route turns use router.Segment: https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/reference/router.Segment-docpage/

    Example:

    var path = route.getPaths().get(0);
    path.getSegments().forEach(function(segment) {
        var segmentPoints = segment.getCoordinates(),
            segmentEndPoint = segmentPoints[segmentPoints.length -1];
    
        map.geoObjects.add(new ymaps.Placemark(segmentEndPoint));
    });