OSRM – Open Street Routing Machine is a open source C++ project and Nominatim is a tool for synthesising address from OSM – Open Source Map data. Have a look at both of them here. These applications are used widely by many organisations to supplement their Map requirements. I am assuming the readers are familiar with the Google Maps API, you can have a look at their analogous functions with OSRM.
Google Maps – Directions API – OSRM-Backend route
Google Maps – Distance Matrix – OSRM-Backend table ( contains only duration )
Google Maps – Geo-coding API – Nominatim
Google Maps – Road API – OSRM-Backend match
In case you have the requirement for the above APIs or any here , go ahead to install OSRM and Nominatim.
Have a look at the size of the osm pbf you would want to use at geofabrik . File size ranges from 100 MB – 33 GB. Your RAM requirements would range from 512 MB – 8 GB and your Swap requirements would range from 1 GB – 100 GB. So, be generous while allocating swap to avoid multiple trials installing. Tutorial to create swap .
To keep the OS updated.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install unattended-upgrades
Go to directory where you would like to have osrm
wget -O map.osm.pbf url_of_the_pbf
The url_of_the_pbf file you got from geofabrik.
Install the dependencies
sudo apt install build-essential git cmake pkg-config \
libbz2-dev libstxxl-dev libstxxl1v5 libxml2-dev \
libzip-dev libboost-all-dev lua5.2 liblua5.2-dev libluabind-dev libtbb-dev
git clone https://github.com/Project-OSRM/osrm-backend.git
sudo make install
osrm-extract data/map.osm.pbf -p osrm-backend/profiles/car.lua
osrm-extract command may not execute successfully. It depends on the map.osm.pbf file. If it does well and good else look for a older versions of file. Also it could be memory issue try using a bigger RAM and swap.
osrm-contract command takes long time to execute. It might fail due to small swap. Again I would give the same advice, try increasing your swap and RAM.
Voilaa.. you have it running on your http://localhost:5000.
Try the following command to
source_longitude, source_latitude, destination_longitude and destination_latitude should be from the country/region you have downloaded.
Installing Nominatim – Dependencies
sudo apt-get update -qq
sudo apt-get upgrade -y
sudo apt-get install -y build-essential cmake g++ libboost-dev libboost-system-dev \
libboost-filesystem-dev libexpat1-dev zlib1g-dev libxml2-dev \
libbz2-dev libpq-dev libgeos-dev libgeos++-dev libproj-dev \
postgresql-server-dev-9.5 postgresql-9.5-postgis-2.2 postgresql-contrib-9.5 \
apache2 php php-pgsql libapache2-mod-php php-pear php-db \
chmod a+x .
git clone --recursive git://github.com/twain47/Nominatim.git
sudo -su postgres
./utils/setup.php --osm-file ../../data/map.osm.pbf --all 2>&1 | tee setup.log
sudo -u postgres createuser www-data
sudo -u postgres psql nominatim
GRANT usage ON SCHEMA public TO "www-data";
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "www-data";
Point your Server to
Nominatim/build/website/ by setting
Also grant permissions to the osrm Directory in
Restart your apache server
sudo service apache restart
You should get your server running on your http://localhost/ . By default its port 80. Try the following command to verify.
<latitude>, <longitude> should be from the country/region you have downloaded.
So guys, its just getting started with free usage for Maps. Theres a long road ahead, keep it going.
To setup your own tile server and provide free maps for your web applications you can read the following blog.