NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hi,

I will be getting a set of lat, longs from the client. I need to connect those points using a free line. I used the polyline feature in the leaflet library. I only get a straight line. I want to draw a line that highlights the road.

Thank you.

asked 10 Feb '20, 03:27

Poojitha's gravatar image

Poojitha
11667
accept rate: 0%


To get a route following roads between points, you need to use a routing engine.

There are several such engines available that you can query for free for light use. For more intensive use, you will typically need to pay.

Engines you could consider include Graphhopper and OSRM (the best free service for the latter is at https://routing.openstreetmap.de/about.html ). Typically you will send an AJAX/fetch request to the routing engine server with your lat/lons, and it will return a polyline which you can draw with Leaflet.

permanent link

answered 10 Feb '20, 10:50

Richard's gravatar image

Richard ♦
30.9k44279412
accept rate: 18%

On the leaflet plugin list, you'll find a Routing section.

All these plugins relies on external services for the calculation, but integration with your map should be easy.

permanent link

answered 10 Feb '20, 11:49

H_mlet's gravatar image

H_mlet
5.4k1781
accept rate: 13%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×74

question asked: 10 Feb '20, 03:27

question was seen: 7,585 times

last updated: 10 Feb '20, 11:49

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum