Easy, flexible routing for Leaflet
About Getting Started Tutorials API DownloadLeaflet Routing Machine is an easy, flexible and extensible way to add routing to a Leaflet map. Using the default is just a few lines of code to add fully functional routing, but you can still customize almost every aspect of the user interface and interactions.
Getting started with Leaflet Routing Machine is easy. Download the files and
include leaflet-routing-machine.css and leaflet-routing-machine.js in a Leaflet page:
[...]
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<link rel="stylesheet" href="leaflet-routing-machine.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="leaflet-routing-machine.js"></script>
[...]
If you prefer, you can also install using NPM:
npm install --save leaflet-routing-machine
To add the basic routing control to your map instance, use this Javascript code:
L.Routing.control({
waypoints: [
L.latLng(57.74, 11.94),
L.latLng(57.6792, 11.949)
]
}).addTo(map);
Note that in the most basic version, the control will not be able to do address lookups (geocoding), so you will have to provide the latitude and longitude of the waypoints. See the tutorials page for information about adding address lookup and much more. You might also want to dive into the API docs for details.
The plugin is free and open source. Leaflet Routing Machine is hosted on GitHub, where you can report issues or bugs.
Feedback and help is always welcome in any form: documentation, tutorials or code. Feel free to add a pull request, or contact me at per@liedman.net.