【问题标题】:totalTime [Leaflet Routing Machine]totalTime [传单路由机]
【发布时间】:2016-03-09 17:48:41
【问题描述】:

我实际上正在使用 Leaflet Routing Machine 为一个学校项目工作,并且对 totalTime 方法有疑问。

    var map = L.map('map');

L.tileLayer('', {
    attribution: ''
}).addTo(map);

L.Routing.control({
    waypoints: [
        L.latLng(45.7979, 4.7178),
        L.latLng(45.5221, 4.8101),
        L.latLng(45.42, 4.35)
    ],
    routeWhileDragging: true,
    language: 'fr'
}).addTo(map);

L.Routing.control({
    waypoints: [
        L.latLng(44.7979, 4.7178),
        L.latLng(45.42, 4.35)
    ],
    routeWhileDragging: true,
    language: 'fr'
}).addTo(map);

window.alert(routes[0].summary.totalTime());

但是 JS 控制台告诉我 routes[] 没有定义。

有什么问题吗?我们应该使用 routes[] 以外的其他东西吗?

【问题讨论】:

标签: javascript routing routes leaflet


【解决方案1】:

您的问题与路由控件上未使用“routesfound”事件有关。尝试在handler内部添加事件并处理距离和时间结果

routeCtr.addTo(map).on('routesfound', function (e) {
        distance = e.routes[0].summary.totalDistance;
        min = e.routes[0].summary.totalTime;
};

试试看。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    相关资源
    最近更新 更多