Reputation:
i am trying to use the Leaflet Routing Machine to display the route between two points. I have implemented these functions exactly like in the example on the Plugin Provider Website. I get two markers but the way isn't displayed.
<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: '© <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.");
});
Upvotes: 1
Views: 4424
Reputation: 59318
Most likely you get this error:
TypeError: Cannot read property 'maneuver' of undefined
since leaflet-routing-machine
library is not compatible with leaflet v0.7.7
, here is a similar reported issue.
So, the solution would be to upgrade leaflet
to version 1.0.0
or above, once updated the route should be printed as expected, here is a demo
Upvotes: 1