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.
L.Routing.Mapbox
; see the alternative routers tutorialNote: Leaflet Routing Machine v3.1.2 and later are compatible with Leaflet 1.0.0 (and release candidates), as well as Leaflet 0.7.
Getting started with Leaflet Routing Machine is easy. Include
leaflet-routing-machine.css
and leaflet-routing-machine.js
in a Leaflet page:
[...]
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.js"></script>
[...]
(For production use, you might want to Download the files
instead of using unpkg.com
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);
Update 2020-04-06: The example above relies on OSRM's demo server. At this moment, the demo server (which is outside scope and control of the plugin's author) is no longer maintained, and its SSL certificate has expired. The plugin will not work unless you configure a routing backend yourself. I am sorry to say that, to my knowledge, there is no good default.
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. You can also try our community chat, the Leaflet Routing Machine gitter.
This prevents Leaflet Routing Machine from displaying a route. The demo server will hopefully be back up soon. Please do not report this as an issue, Leaflet Routing Machine has no control over the demo server.
In production, set up your own OSRM instance, or pay a service provider.