<h1>Open Street Maps<aclass="headerlink"href="#open-street-maps"title="Permalink to this heading"></a></h1>
<p>Much like Google Maps, <codeclass="docutils literal notranslate"><spanclass="pre">Openstreetmaps</span></code> 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 <em>plug-and-play</em> 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.</p>
<sectionid="osrm">
<h2>OSRM<aclass="headerlink"href="#osrm"title="Permalink to this heading"></a></h2>
<p><strong>O</strong>pen <strong>S</strong>ource <strong>R</strong>outing <strong>M</strong>achine (OSRM) is a project that allows you to calculate distances from a OSM map.
See more about the project <aclass="reference external"href="https://project-osrm.org/">here</a></p>
<sectionid="setup">
<h3>Setup<aclass="headerlink"href="#setup"title="Permalink to this heading"></a></h3>
<p>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:</p>
<divclass="highlight-console notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">#</span>Download The Netherlands
<p>Now you can use curl to do requests to port <codeclass="docutils literal notranslate"><spanclass="pre">5998</span></code>.</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>When using Google Maps coordinates to send requests to OSRM, make sure that the Longitude and Latitude coordinates are not swapped.</p>
</div>
</section>
</section>
<sectionid="nominatim">
<h2>Nominatim<aclass="headerlink"href="#nominatim"title="Permalink to this heading"></a></h2>
<p>As it turns out, <codeclass="docutils literal notranslate"><spanclass="pre">OSRM</span></code> is a very good routing engine but it can’t do geolocation. To solve this <codeclass="docutils literal notranslate"><spanclass="pre">Nominatim</span></code> was used to resolve postal codes to coordinates.</p>
<p>This will result in a website that is accessible on port 5999 to which you can send queries.</p>
</section>
<sectionid="ip-firewall">
<h2>IP Firewall<aclass="headerlink"href="#ip-firewall"title="Permalink to this heading"></a></h2>
<p>Procesing routing data is hard.
In order to prevent bots from misusing these interfaces a firewall rule was added to only allow incomming traffic from specific ip addresses.</p>
<divclass="highlight-console notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">$ </span>sudo ufw allow from <ip_addr> to any port <spanclass="m">5998</span>
<spanclass="gp">$ </span>sudo ufw allow from <ip_addr> to any port <spanclass="m">5999</span>
<h2>Tile Server<aclass="headerlink"href="#tile-server"title="Permalink to this heading"></a></h2>
<p>In order to also serve tiles and be fully independent from <codeclass="docutils literal notranslate"><spanclass="pre">Google</span><spanclass="pre">Maps</span></code> a tileserver was also started.
For this the previously donwloaded .pbf file needs to be imported and a postgresql database was used to <em>hopefully</em> speed up the performance.</p>
<p>First we need to import the data, then start a tileserver.</p>
<spanclass="gp">$ </span>docker run -v <spanclass="s2">"</span><spanclass="si">${</span><spanclass="nv">PWD</span><spanclass="si">}</span><spanclass="s2">/data/netherlands-latest.osm.pbf:/data.osm.pbf"</span> -v openstreetmap-data:/var/lib/postgresql/12/main overv/openstreetmap-tile-server:1.3.10 import
<spanclass="go">Run tile server</span>
<spanclass="gp">$ </span>docker run -p <spanclass="m">5997</span>:80 -v openstreetmap-data:/var/lib/postgresql/12/main -d overv/openstreetmap-tile-server:1.3.10 run
</pre></div>
</div>
<p>This will open a map server at port <strong>5997</strong>. When navigating to <em>http://www.herreweb.nl:5997/tile/0/0/0.png</em>, a world map is shown.</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>The import step took over 2 hours on a 6-core <em>slow</em> server(Intel Xeon E5-2620 v2). The map server is not fast either, but faster after loading all the map tiles.</p>