Leaving Google Maps? Use OSRM for Routing

Janaka Chathuranga
Sep 23, 2018 · 2 min read

Google Map APIs comes in handy except for its pricing. Recently Google Maps API prices were increased by about 10 times for premium features such as Places and Directions, etc. In that case some of your business use cases may not survive this cost. So what are the options we have? This guide shows to setup such a service on your own computer.

Good Bye..! Just kidding… only maps. Okay? ;)

Part 1: Directions

As alternative s there are several similar services such as MapQuest, Being Maps but I am not going to talk about services here. Here I am going to guide you to set up a routing engine on your own VM to solve directions.

OSRM (Open Street Routing Machine) is a powerful and efficient routing machine for engine to solve shortest paths in road networks. It is completely open source and you can host it in your machine without paying for a license.

Further it has all the required API’s you need from a routing engine and all these services are open source.

I tried several similar engines but I can recommend OSRM. Others had many issues. For and example the popular Graph Hopper server doesn't provide distance matrix API for free, it’s a premium feature. The OSRM is completely free and open source. ❤

These are the APIs available in OSRM

Setting Up OSRM


  • A Docker Installed Computer

Lol.. Sorry. You don’t actually need docker to run OSRM but here I am going to use docker because it’s easier and avoid many environment configuring steps. If you don’t know how to install docker follow this links. ,

Step 1: Download OSM.PBF file for your territory

Its’ not that difficult. All you have to do is visit this site

Find the region you want and download the file.

I am downloading the file for Sri Lanka with following command.


Step 2: Start server with docker

docker run -t -i -p 5000:5000 -d -v $(pwd):/data osrm/osrm-backend osrm-routed --algorithm mld /data/sri-lanka-latest.osrm

This will start an HTTP server on port 5000.

See. It’s pretty easy. (Thanks to Docker ;)

That’s all you are ready to route!!

Check whether it’s working

Navigate to following url.


Now you will get the routing results as a json.

{"code":"Ok","routes":[{"geometry":"kruh@q`mfNxBu`@nzEkcCfWmoBgs@}cBpoB}jJtkAoDtzCo`BnlKu{@pbKl^|eLmqFn`E}j@~qL_bGsU{vA_k@mDmkBomCtaA{uC`cBwrBsh@w}@~N}XxvBye@viAewBjwFmvApOxd@`fEs@jr@xo@","legs":[{"steps":[],"distance":87717.5,"duration":5342,"summary":"","weight":5342}],"distance":87717.5,"duration":5342,"weight_name":"routability","weight":5342}],"waypoints":[{"hint":"...... }]}

For more details about OSRM API’s visit their .