我怎样才能得到 L.Routing.control 的距离和时间?
How can I get the distance and time from L.Routing.control?
我正在传单地图上绘制路线,效果很好,在控件中显示了距离和预计到达时间。有没有办法将它们都提取并保存?
代码为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');
});
我正在传单地图上绘制路线,效果很好,在控件中显示了距离和预计到达时间。有没有办法将它们都提取并保存?
代码为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');
});