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.
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
- Nearest service
- Route service — Similar to Directions API
- Table service — Similar to Distance Matrix API
- Match service
- Trip service — Solves Traveling Salesman Problem (Route Optimizations)
- Tile service — Map Tiles
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. Ubuntu, Windows
Step 1: Download OSM.PBF file for your territory
Its’ not that difficult. All you have to do is visit this site http://download.geofabrik.de
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.
For more details about OSRM API’s visit their docs.