1

I am developing a GIS in QGIS and I want to get the user's current location, then according to the user's second point selection, I want to generate a route between these two points. If possible, I want routing to be based on walking, not car.

I want to use OpenStreetMap as the base map.

Any idea how I can achieve this?

I want this to be done on a web map after creating it using the qgis2web plugin. I have looked at OSRM but I can't find out how exactly to use it on this system.

  • OSRM has a REST API which you can use in your system to get the route geometry. Get started sending a simple route request to OSRM and show it in your map. – Mesa May 23 '18 at 11:04
  • Hey @Mesa , thanks for the response. I am stuck on how I can start on that, can you please show me more directions, links perhaps? – Farai Mugaviri May 23 '18 at 12:18
  • 1
    Because you want to do this in the webmap generated by qgis2web, this isn't really a QGIS issue. Can you retag your question with Leaflet and/or OpenLayers, depending on which format you are exporting your map in? – Tom Chadwin May 23 '18 at 14:42
  • Ok, thanks @Tom Chadwin. Any suggestions on how I can work with it? The map is being generated by OpenLayers – Farai Mugaviri May 23 '18 at 17:33
1

As suggested by Mesa you can start by generating a route request which should provide you with an output json that you can parse to retrieve the route. You can then create a vector layer and add it to the map.

OSRM API Documentation provides all the necessary information (including example requests) to get you started.

Example:

http://router.project-osrm.org/route/v1/foot/13.388860,52.517037;13.397634,52.529407?geometries=geojson

Output:

{
  "routes": [
    {
      "geometry": {
        "coordinates": [
          [
            13.3888,
            52.517033
          ],
          [
            13.388625,
            52.518883
          ],
          [
            13.388024,
            52.52175
          ],
          [
            13.388898,
            52.521997
          ],
          [
            13.391643,
            52.522074
          ],
          [
            13.391718,
            52.522858
          ],
          [
            13.393549,
            52.526228
          ],
          [
            13.392425,
            52.528233
          ],
          [
            13.397631,
            52.529432
          ]
        ],
        "type": "LineString"
      },
      "legs": [
        {
          "summary": "",
          "weight": 627.6,
          "duration": 458.8,
          "steps": [],
          "distance": 1879.4
        }
      ],
      "weight_name": "routability",
      "weight": 627.6,
      "duration": 458.8,
      "distance": 1879.4
    }
  ],
  "waypoints": [
    {
      "hint": "598JgGxZ5oQoAAAAOgAAAA8AAAAAAAAAeOI0QY6li0FoZYRAAAAAACgAAAA6AAAADwAAAAAAAAByoQAAAEzMAKlYIQM8TMwArVghAwEA3wr1yOx5",
      "name": "Friedrichstraße",
      "location": [
        13.3888,
        52.517033
      ]
    },
    {
      "hint": "uZsTgLfVvIEOAAAADAAAAHMBAAAAAAAA4pzIQFu_j0CGdCVDAAAAAA4AAAAMAAAAcwEAAAAAAAByoQAAf27MABiJIQOCbswA_4ghAwIAnxD1yOx5",
      "name": "Torstraße",
      "location": [
        13.397631,
        52.529432
      ]
    }
  ],
  "code": "Ok"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.