javascriptleafletopenstreetmapmaprouteosrm

How to set OSRM (Open Source Routing Machine) route markers by a javascript?


I tried OSRM online demo [1] and Front End source codes [2]

  1. http://map.project-osrm.org/
  2. https://github.com/Project-OSRM/osrm-frontend

There we can set start and set location on text boxes. In order to set route markers between start and end we need to click on the path and drag to required point on the map.

Is there anyway to set these intermediate points dynamically using JavaScript?


Solution

  • Of course OSRM implements an API that can be called via JS and returns JSON routes:
    https://github.com/Project-OSRM/osrm-backend/wiki/Server-api

    You need to repect the API usage policy and other legal aspects.