Offline‑First Navigation: Build a Self‑Hosted Map Tile Server and Router for Privacy
MapsPrivacyRaspberry Pi

Offline‑First Navigation: Build a Self‑Hosted Map Tile Server and Router for Privacy

sselfhosting
2026-01-31
9 min read
Advertisement

Run private, offline navigation by self‑hosting OSM tiles and routing (OSRM/Valhalla) on a Pi or small server—step‑by‑step, secure, and production‑ready.

Hook: Take navigation off Big Tech and onto your own hardware

Are you tired of routing providers tracking your trips, or dependent on a single cloud provider for maps and navigation? If you run services for yourself or your team, you can keep navigation private and offline‑first by self‑hosting OpenStreetMap tiles and a routing engine on a small server or Raspberry Pi 5. This guide walks you through a practical, production‑ready setup (OSM tiles + OSRM or Valhalla) that works on modest hardware in 2026.

Executive summary — what you'll get and why it matters

In this article you'll learn how to:

  • Choose the right architecture (vector tiles vs raster tiles; OSRM vs Valhalla).
  • Prepare hardware and OS (Raspberry Pi 5 or small x86 server / Mac mini recommended).
  • Import OSM data for a region using osm2pgsql or download MBTiles.
  • Serve vector tiles with Tegola or MBTiles with tileserver‑gl.
  • Install and run routing with OSRM (small & fast) or Valhalla (feature rich).
  • Integrate on‑device or web clients (MapLibre/Leaflet or mobile apps) and secure the stack.

Follow the steps below to create an offline‑first, privacy‑preserving navigation service you control.

Recent trends (late 2025 → early 2026) make self‑hosting practical for admins and devs:

  • Edge hardware improved: the Raspberry Pi 5 and ARM SBCs are powerful enough to run vector tile servers and small routing engines for regions.
  • Wider ARM support in Docker images and Go-based tools (Tegola, Maplibre stack) simplifies deployment on Pi.
  • Prebuilt MBTiles and region extracts from projects like OpenMapTiles and Geofabrik reduce processing time and storage needs.
  • Privacy and security expectations rose after cross‑service data aggregation stories; organizations want local control of location data.

Bottom line: You can now run a robust offline map and routing service for a city or country on a low‑power server without sacrificing features.

Architecture choices — pick the right stack

Vector vs raster tiles

Vector tiles (Mapbox Vector Tile / PBF) are the most efficient choice for edge devices: smaller storage, client‑side styling (MapLibre), and more future‑proof. For Pi‑class hardware, use prebuilt MBTiles or Tegola + PostGIS.

Raster tiles (PNG) are simpler for legacy clients but expensive to render on the fly. Only use raster rendering (mod_tile + renderd) if you need identical cartography to tile servers and are prepared for heavy CPU usage.

Routing: OSRM vs Valhalla

  • OSRM — fast, lean, and a great fit for single‑profile car routing on constrained hardware. Build extracts, run contraction hierarchies, and route with osrm-routed. Lightweight and well documented.
  • Valhalla — more features (multi‑modal, isochrones, costing profiles). A better choice if you need bicycle, pedestrian, transit, or advanced costing, but heavier to build and run.

What you'll need (hardware & software)

  • Raspberry Pi 5 with 8GB RAM (recommended) or a small x86 VM/NUC or Mac mini. For bigger extracts, use a VPS with 4+ vCPU and 8–16 GB RAM.
  • Fast storage: NVMe or SSD (64–512 GB depending on region). Avoid relying on SD card for databases.
  • Ubuntu Server 24.04 (ARM or x86) or Raspberry Pi OS 64‑bit. Docker + Docker Compose (see modern developer onboarding flows for reproducible environments).
  • Tools: Docker, Docker Compose, Postgres + PostGIS, osm2pgsql (or prebuilt MBTiles), Tegola (vector tiles), tileserver‑gl (MBTiles), osrm‑backend/valhalla containers.
  • OSM extracts: Geofabrik (regional PBF), or prebuilt MBTiles from OpenMapTiles.

Step‑by‑step deployment (vector tiles + OSRM) — the Pi‑friendly path

The following is a pragmatic path for most users: use vector tiles served by Tegola (lightweight Go server) fed from PostGIS and a routing engine using OSRM for car routes. This combo runs well on Pi 5 and small servers.

1) Prepare OS and Docker

Install Ubuntu 24.04 (or Raspberry Pi OS 64‑bit). Then install Docker and Docker Compose (make sure Docker supports ARM if on Pi).

sudo apt update && sudo apt upgrade -y
sudo apt install -y docker.io docker-compose
sudo usermod -aG docker $USER

Reboot or re‑login to apply the docker group change.

2) Download OSM data (choose region)

Use Geofabrik extracts for countries/regions. For a Pi, start with a city or small country extract (e.g., switzerland-latest.osm.pbf).

mkdir -p ~/osm-data && cd ~/osm-data
wget https://download.geofabrik.de/europe/germany-latest.osm.pbf -O germany.osm.pbf

3) Run Postgres + PostGIS and import with osm2pgsql

Use Docker Compose to start postgres/postgis and osm2pgsql import. Example compose for Postgres:

version: '3.8'
services:
  db:
    image: postgis/postgis:15-3.3
    volumes:
      - ./pgdata:/var/lib/postgresql/data
      - ./osm-data:/osm-data
    environment:
      POSTGRES_PASSWORD: example
      POSTGRES_DB: gis
    ports:
      - '5432:5432'

Start Postgres:

docker compose up -d db

Import using osm2pgsql (either install on host or use a container). Example (host install):

sudo apt install -y osm2pgsql
osm2pgsql --create --database gis --username postgres --host 127.0.0.1 --slim --drop --cache 2000 --hstore ./osm-data/germany.osm.pbf

Tune --cache based on RAM. On Pi 5 with 8GB, 2GB is safe for city extracts; larger extracts need more RAM or an external swap/SSD.

4) Configure Tegola to serve vector tiles

Tegola connects to PostGIS and serves Mapbox vector tiles. It's Go‑based, fast, and ARM friendly.

Install Tegola (Docker image available) and create a simple config file tegola.toml referring to the Postgres DB and layers. Minimal example:

[web]
port = ":8080"

[providers]
  [providers.postgis]
  type = "postgis"
  host = "db"
  port = 5432
  database = "gis"
  user = "postgres"
  password = "example"

[layers]
  [[layers]]
  id = "roads"
  provider_layer = "public.planet_osm_line"
  geometry_field = "way"
  srid = 3857

Run Tegola with Docker Compose:

services:
  tegola:
    image: tegola/tegola:v1.27.0
    volumes:
      - ./tegola.toml:/etc/tegola/tegola.toml
    ports:
      - '8080:8080'
    depends_on:
      - db

5) Build and run OSRM for routing

OSRM works well for car routing. Build a contracted graph and serve it.

docker run --rm -v $(pwd)/osm-data:/data osrm/osrm-backend osrm-extract -p /opt/car.lua /data/germany.osm.pbf
docker run --rm -v $(pwd)/osm-data:/data osrm/osrm-backend osrm-contract /data/germany.osrm

Then run the server:

docker run -d -p 5000:5000 -v $(pwd)/osm-data:/data osrm/osrm-backend osrm-routed --algorithm mld /data/germany.osrm

Test routing with a curl request:

curl "http://localhost:5000/route/v1/car/8.681495,49.41461;8.687872,49.420318?overview=false"

Optional: Valhalla for advanced routing

If you need multimodal routing (transit, bicycle customization, time‑dependent costing), deploy Valhalla. It is heavier but feature rich.

High‑level steps:

  1. Install valhalla_build_tiles to convert PBF to tile files.
  2. Start the valhalla_service Docker image with access to the build output.
  3. Configure costing profiles in Valhalla's JSON config for walking/biking/transit.

Valhalla's docs (project repository) contain up‑to‑date commands; use the prebuilt Docker image for ARM when on a Pi.

Client integration: web and mobile

On the web, MapLibre GL + your Tegola or tileserver‑gl endpoint instantly provides an offline‑capable map. Use OSRM/Valhalla for routing API calls and render routes as GeoJSON polylines.

fetch('/tiles/{z}/{x}/{y}.pbf') // vector tiles
fetch('http://yourserver:5000/route/v1/car/…') // OSRM

For mobile offline use, consider:

  • OsmAnd / Maps.me — they accept MBTiles for offline maps and have routing engines (some support external tile/routing sources).
  • Custom Android app using MapLibre and direct queries to your routing container over local network or VPN. See our field kit guidance for on‑site apps and compact setups (field kit review).

Security, TLS, and network setup

Keep your self‑hosted navigation safe:

  • Place services behind an Nginx reverse proxy and enable TLS with Let’s Encrypt for public access or a self‑signed cert for LAN only.
  • Use firewall rules (ufw) to restrict ports to your network and only open necessary ports.
  • Run services under non‑root users and enable container resource limits to avoid runaway load.
  • Log access and rotate logs; monitor with Prometheus + Grafana for CPU, RAM, disk I/O and response latencies.

Backups and updates — operational best practices

Key data to back up:

  • Postgres/PostGIS database dump (pg_dump) or file system snapshot.
  • MBTiles files and OSRM .osrm files (these are your prebuilt tiles/graphs).
  • Tegola/Valhalla/OSRM configuration files.

Recommended schedule:

  • Daily small backups (config, incremental DB dumps) for active setups.
  • Weekly full backups for MBTiles and .osrm/.valhalla files (they're big but rarely change unless you reimport data).

Performance tuning and pitfalls

Practical tips learned from real deployments:

  • Use NVMe or SSD for Postgres and OSRM files. SD cards are unreliable and slow under DB load.
  • Set Postgres shared_buffers to ~25% RAM and tune work_mem for osm2pgsql imports.
  • Enable OSRM's MLD algorithm for faster queries with reduced memory footprint on large extracts.
  • For Tegola, configure caches and use HTTP caching (Cache‑Control) for static tiles.
  • When testing on Pi, start small (city extract) and scale to larger regions only once comfortable.

Advanced: bring AI and local intelligence to navigation (2026 preview)

With the arrival of faster SBCs and hardware accelerators (AI HATs for Pi 5 and ARM servers), expect edge‑level enhancements in 2026:

  • Local anomaly detection — detect road closures or unusual traffic patterns from device telemetry without sending data to cloud vendors.
  • Client‑side rerouting using ML models for better personalization of routes (energy‑efficient for EVs, accessibility-aware routes).
  • Hybrid setups where heavy precomputation runs in a nearby VPS while the Pi serves tiles & routing queries locally for latency/privacy. For design patterns and edge tradeoffs see work on edge‑powered deployments.

Plan your architecture so that ML inference and model updates can be deployed to the edge without rearchitecting the entire maps stack.

Checklist — turn this article into a working plan

  • Choose hardware: Pi 5 (8GB + NVMe) or small x86 box.
  • Pick tile strategy: Tegola + PostGIS for dynamic vector tiles, or MBTiles + tileserver‑gl for static vector.
  • Select routing engine: OSRM for lean car routing, Valhalla for multimodal needs.
  • Download region extract (Geofabrik) or MBTiles (OpenMapTiles).
  • Import, build graphs, start containers, and test API endpoints locally.
  • Secure with Nginx + TLS and configure backups/monitoring.

"Self‑hosting maps and navigation is no longer an academic exercise — it's now practical for teams and labs who prioritize privacy, control, and resiliency."

Actionable takeaways — start today

  • If you're evaluating hardware: get a Raspberry Pi 5 with NVMe HAT and 8GB RAM. Use a small test region from Geofabrik and deploy the stack in Docker first.
  • Want the fastest route to a working demo? Download an OpenMapTiles MBTiles file for your city and run tileserver‑gl + osrm Docker images. No heavy imports.
  • Need multimodal features? Plan for Valhalla on a slightly larger machine and allocate extra RAM/disk for the build step.

Further reading & next steps

Next actions to deepen the system:

  • Integrate a local mobile VPN or hotspot so phones use the Pi when on the local network.
  • Automate updates: use CI jobs to rebuild graphs/tiles monthly with fresh OSM extracts.
  • Contribute back to the community: share your MBTiles or Docker Compose recipes for your region and consider on‑demand printing or souvenirs at popups (see 3D printer souvenir prototyping).

Call to action

If you want a tailored deployment plan for your team (region size, hardware recommendations, Docker Compose tuned for Pi), I can produce a customized playbook with commands, monitoring dashboards, and backup scripts. Reply with your target region (city/country), preferred hardware, and whether you want OSRM or Valhalla — I'll draft a ready‑to‑run Docker Compose + import script you can use the same day.

Advertisement

Related Topics

#Maps#Privacy#Raspberry Pi
s

selfhosting

Contributor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.

Advertisement
2026-02-03T18:54:02.893Z