Kick Start — Open Source Routing Machine Set-Up

cheerio google map, greeting open-source map

Tony Wilson jesuraj
IVYMobility TechBytes
4 min readJul 10, 2020

--

So this blog will be about Setting up OSRM (Open Source Routing Machine) with demo video and explaining HTTP requests

What is OSRM?

OSRM in Open Source Routing Machine. In simple words, you can create your map application like google map using OSRM (FOR FREE!!)

Why OSRM?

  • Powerful and efficient engine routing machine for solving shortest road tracks.
  • It’s fully open-source and you can host it on your computer without paying for a license

So say bye to google map and create your own map company by using OSRM

How to use it?

I tried OSRM set-up without docker and end up with frustration

Step 0: Docker set-up (If not before)

Ubuntu users just go with sudo apt-get docker . Yes, your docker is ready.

Windows users have fun here and Mac user have fun here

Step 1: Getting your territory OSM.PBF file

Or

Step 2: Pre-processing

This part is extracting your downloaded osm.pbf . This will help to start a routing engine HTTP server on port 5000 (For sample)

(Ubuntu-users just add sudobefore docker command)

My file name was berlin so I went with berlin (you needed to go with your map or osm.pbf file name)

The flag -v "${PWD}:/data" creates the directory /data inside the docker container and makes available the current "{$PWD}”working directory there. Inside the container, the file refers to on the host "${PWD}/berlin-latest.osm.pbf"

And Now

This is how your files will be looking after extracting osm.pbf

(Note: If got any error like files are missing, please repeat from step2 again without deleting any files )

Step 3: Getting Response

And now in your cmd

Or in browser

And 13.388860,52.517037;13.385983,52.496891 are latitude and longitude for two places (which you need to find the distance between them)

This is HTTP requests to find a distance between the two-place using latitude and longitude

Let’s see different HTTP requests at below

And yes you will get an answer through a JSON like ( Note: If any error you can also call me at 3:00 AM)

I will be explaining more about this JSON in my next blog soon

Here I have attached some demo video on how to host on localPort after extracting osm.pbf

Now Local port is ready to get requests

Results in JSON (Happy ending)

Requests

Okay let me explain it HTTP requests

Version

The version of the protocol implemented by the service

Profile

Typically it is car , bike or foot

Coordinates

Just longitude and latitude in-service format which you needed

Service

Service has one of the following values: route , nearest , table , match , trip , tile

Nearest service

Snaps a street network coordinate, and returns the nearest n matches.

Where coordinates only support a single entry in {longitude}, {latitude}.

Example

Example Response

Route service

Finds the fastest route between coordinates in the supplied order

Example

Table service

Computes the duration of the fastest route between all pairs of supplied coordinates

Example

And you can also select sources and destinations by just adding it index

Unlike other array encoded options, the length of sources and destinations can be smaller or equal to the number of input locations

Example

Trip service

The trip plugin solves the Traveling Salesman Problem using a greedy heuristic (farthest-insertion algorithm)

So if I confused you or frustrated you or any wrong in my blog, yell me at comment box

Yes you can also yell at my twitter and if any error you can also call me at 3:00 AM

--

--