How to create routes using Leaflet #81
Unanswered
GuillermoDylan
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How to create routes
Hello guys!
This is a quick guide filled mainly with short examples and references on how to create a route on maps given by the Leaflet library.
Using the MapQuest API
MapQuest is a JavaScript library for interactive maps, geocoding, directions, and traffic. It can be integrated with Leaflet and allows to create routes given two different points in the map, or even two different city names or directions.
This API requires the use of a API key.
Example
Given a map, we can create a route for two different places over it in the following way:
As simple as it may seem, I recommend checking the following references, as they have a complete version of the code that is already set and itegrated with a leaflet map.
References:
Using Leaflet Routing Machine
Leaflet Routing Machine is an open source API service to create routes over Leaftlet maps.
It does not require a lot of coding and seems to be of easy use.
Unfortunately, it has not been updated since 2021, and some of the plugins it requires might be outdated.
Example
We will need the following css styles and links:
We will need to install its dependency:
npm install --save leaflet-routing-machine
To add the basic routing control to your map instance, use this Javascript code:
References:
Beta Was this translation helpful? Give feedback.
All reactions