【问题标题】:Leaflet Routing Machine传单路由机
【发布时间】:2018-10-19 12:28:24
【问题描述】:

我正在尝试使用 Leaflet Routing Machine 来显示两点之间的路线。我已经完全按照插件提供商网站上的示例实现了这些功能。我得到了两个标记,但没有显示路径。

<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
  <head profile="http://gmpg.org/xfn/11">
    <title>Wanderrouten24</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css"   href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
    <link rel="stylesheet" href="leaflet-routing-machine-3.2.7/dist/leaflet-routing-machine.css" />
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'></script>
    <script type='text/javascript' src='http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js'></script>
    <script src="leaflet-routing-machine-3.2.7/dist/leaflet-routing-machine.js"></script>
  </head>
  <body>
  <div id="map" style="width: 800px; height: 440px; border: 1px solid #AAA;"></div>
    <script type='text/javascript' src='maps/createRoute.js'></script>
  </body>
</html>

JS:

var map = L.map( 'map', {
  center: [20.0, 5.0],
  minZoom: 2,
  zoom: 2
});

L.Routing.control({
  waypoints: [
      L.latLng(49.47748, 8.42216),
      L.latLng(49.47648, 8.32216)
  ],
  routeWhileDragging: true
}).addTo(map);

L.tileLayer( 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
  subdomains: ['a', 'b', 'c']
}).addTo( map );

map.setView([49.47748, 8.42216], 15);

map.locate({setView: true, watch: true}) /* This will return map so you can do chaining */
.on('locationfound', function(e){})
.on('locationerror', function(e){
    console.log(e);
    alert("Location access denied.");
});

【问题讨论】:

    标签: javascript web routing leaflet


    【解决方案1】:

    您很可能会收到此错误:

    TypeError: Cannot read property 'maneuver' of undefined

    由于leaflet-routing-machine libraryleaflet v0.7.7 不兼容,here 是一个类似的报告问题。

    因此,解决方案是将leaflet 升级到1.0.0 或更高版本,一旦更新,路线应按预期打印,here is a demo

    【讨论】:

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