Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapbox Directions API addWaypoint

I am working on a application and I want to get directions for more than 2 points

Which I assume other than origin and destination other locations are waypoints.

So I am trying to use directions.setWaypoint() to add waypoints to the map but it doesn't work

please help for me to understand what I do wrong.

I have created a JsFiddle https://jsfiddle.net/3uzm1nh0/1/

and this is the documentation I am referring to https://github.com/mapbox/mapbox-directions.js/blob/mb-pages/API.md

Thanks in advance.

like image 408
Tharindu Avatar asked Apr 28 '26 03:04

Tharindu


1 Answers

You need someting like this

 // = L.mapbox.directions({profile: 'mapbox.driving'})
var directions = L.mapbox.directions();
var directionsLayer = L.mapbox.directions.layer(directions).addTo(map);
var directionsRoutesControl = L.mapbox.directions.routesControl('routes', directions).addTo(map);
directions.setOrigin(L.latLng(14.6059596413528, -90.49169592683657));

directions.addWaypoint(0,L.latLng(14.60026436463006, -90.49669902226937));
directions.addWaypoint(1,L.latLng(14.59689160135752, -90.49520561914318));
directions.addWaypoint(2,L.latLng(14.60036292858185, -90.49586222238077));

directions.setDestination(L.latLng(14.6059596413528, -90.49169592683657));
directions.query();
like image 169
Sergio Ovalle Avatar answered May 01 '26 06:05

Sergio Ovalle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!