Leaflet Routing Machine API - 以航路点为起点和终点的路线

时间:2015-05-01 16:21:57

标签: api routing leaflet

当两次添加航点时(作为路线的起点和终点,路线不会显示。

如何更改代码以使其有效?

L.Routing.control({
waypoints: [
    L.latLng(lat1, long1),
    L.latLng(lat2, long2),
    L.latLng(lat1, long1,
],
serviceUrl: 'http://router.project-osrm.org/viaroute',
routeWhileDragging: false,
addWaypoints: false,
lineOptions: {
  styles: [{color: 'black', opacity: 0.15, weight: 9}, {color: 'white',    opacity: 0.8, weight: 6}, {color: 'orange', opacity: 1, weight: 2}]
}

由于

1 个答案:

答案 0 :(得分:1)

L.Routing.control({
waypoints: [
L.latLng(lat1, long1),
L.latLng(lat2, long2),
L.latLng(lat1, long1,
],
serviceUrl: 'http://router.project-osrm.org/viaroute',
routeWhileDragging: false,
addWaypoints: false,
lineOptions: {
  styles: [{color: 'black', opacity: 0.15, weight: 9}, {color: 'white',       opacity: 0.8, weight: 6}, {color: 'orange', opacity: 1, weight: 2}]
}

您的代码需要a)在最后一个航点的末尾: L.latLng(lat1,long1)代替L.latLng(lat1,long1,