gpt4 book ai didi

javascript - 如何从 L.Routing.control 获取距离和时间?

转载 作者:行者123 更新时间:2023-11-29 10:27:56 38 4
gpt4 key购买 nike

我在传单 map 上绘制路线,效果很好,在控件中显示距离和预计到达时间。有没有办法提取它们并保存它们?

L.Routing.control 的代码

function getroute() {
myroutewithout = L.Routing.control({
waypoints: [
L.latLng(window.my_lat, window.my_lng),
L.latLng(window.job_p_lat, window.job_p_lng)
],show: true, units: 'imperial',
router: L.Routing.mapbox('API-KEY-HERE'),
createMarker: function(i, wp, nWps) {
if (i === 0 || i === nWps + 1) {
// here change the starting and ending icons
return mymarker = L.marker(wp.latLng, {
icon: operatoricon
});
} else {
return job_start = L.marker(wp.latLng, {
icon: jobicon
});
}
}
}).addTo(map);

最佳答案

您可以使用此 issue 中的代码实现此目的

var routeControl = L.Routing.control({...});
...
routeControl.on('routesfound', function(e) {
var routes = e.routes;
var summary = routes[0].summary;
// alert distance and time in km and minutes
alert('Total distance is ' + summary.totalDistance / 1000 + ' km and total time is ' + Math.round(summary.totalTime % 3600 / 60) + ' minutes');
});

Demo

关于javascript - 如何从 L.Routing.control 获取距离和时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53988872/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com