Much like Google Maps, ``Openstreetmaps`` is a map that allows you to navigate the world.
The main difference being that OSM is free and can be self hosted.
However there is not a *plug-and-play* solution that will host your own maps.
It turns out that hosting your own maps, including geolocation and calculating distances is quite a big task, especially if you want to suppor the whole world.
OSRM
####
**O**\pen **S**\ource **R**\outing **M**\achine (OSRM) is a project that allows you to calculate distances from a OSM map.
See more about the project `here <https://project-osrm.org/>`_
Setup
-----
Setting OSRM up is straightforward, but it requires you to the same docker container several times. In short the commands for the Netherlands are as follows:
Now you can use curl to do requests to port ``5998``.
..note::
When using Google Maps coordinates to send requests to OSRM, make sure that the Longitude and Latitude coordinates are not swapped.
Nominatim
#########
As it turns out, ``OSRM`` is a very good routing engine but it can't do geolocation. To solve this ``Nominatim`` was used to resolve postal codes to coordinates.
In order to also serve tiles and be fully independent from ``Google Maps`` a tileserver was also started.
For this the previously donwloaded .pbf file needs to be imported and a postgresql database was used to *hopefully* speed up the performance.
First we need to import the data, then start a tileserver.
..code-block:: console
Import data
$ docker run -v "${PWD}/data/netherlands-latest.osm.pbf:/data.osm.pbf" -v openstreetmap-data:/var/lib/postgresql/12/main overv/openstreetmap-tile-server:1.3.10 import
Run tile server
$ docker run -p 5997:80 -v openstreetmap-data:/var/lib/postgresql/12/main -d overv/openstreetmap-tile-server:1.3.10 run
This will open a map server at port **5997**. When navigating to *http://www.herreweb.nl:5997/tile/0/0/0.png*, a world map is shown.
..note::
The import step took over 2 hours on a 6-core *slow* server(Intel Xeon E5-2620 v2). The map server is not fast either, but faster after loading all the map tiles.