【问题标题】:Mapbox Directions API addWaypointMapbox Directions API addWaypoint
【发布时间】:2015-11-17 18:45:59
【问题描述】:

我正在处理一个应用程序,我想获得超过 2 个点的路线

我认为除了起点和目的地之外的其他位置都是航路点。

所以我正在尝试使用 Directions.setWaypoint() 向地图添加航点,但它不起作用

请帮助我了解我做错了什么。

我创建了一个JsFiddle https://jsfiddle.net/3uzm1nh0/1/

这是我指的文档https://github.com/mapbox/mapbox-directions.js/blob/mb-pages/API.md

提前致谢。

【问题讨论】:

  • 如果要获取超过 2 个点的路线,不止一次调用 API 不是更好吗?如果您需要从 A 到 B 和从 C 到 D 的方向,我不确定航路点是否会对您有所帮助?也许您可以更好地解释您想要实现的目标?
  • 嗨@kmandov,我实际上想做的是制作一张地图,以便用户可以按他们想要访问的顺序输入位置名称,并在单个地图中获取这些位置的方向。它是一种旅行计划。例如,在谷歌中,我们可以获取 2 个位置之间的方向,我们可以向地图添加更多目的地,它将显示如何绘制 A、B、C ......我想对 mapbox 地图方向.js 做同样的事情.如果有任何不清楚的地方,请告诉我。感谢您的帮助

标签: mapbox directions driving-directions


【解决方案1】:

你需要这样的东西

 // = 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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 2019-07-22
    相关资源
    最近更新 更多