3

我在传单地图上画了一条路线,效果很好,并且在控件中显示了距离和预计到达时间。有没有办法提取它们并保存它们?

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);
4

1 回答 1

7

您可以使用此问题中的代码来实现

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');
});

演示

于 2018-12-31T18:14:55.967 回答