Fork me on GitHub

Leaflet Routing Machine

Easy, flexible routing for Leaflet

About Getting Started Tutorials API Download


About

Leaflet 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.

Features

Getting started

Note: 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. 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.

Help, problems and contributing

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.


Copyright © 2015 Per Liedman, released under ISC License. Logo by Alexey Ivanov, released under Creative Commons CC-BY 3.0.
×

Sorry! The OSRM demo server appears down, or a network error occured.

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.