Gpsdrive with Openstreetmap

This article is outdated. They changed something that prevents Mapnik from working :-(

Will review when I have more time...

Want an open source navigation system, using open source maps? Read on!

Install the software:

sudo aptitude install postgresql postgresql-client postgresql-contrib postgresql-8.4-postgis
sudo aptitude install osm2pgsql gpsdrive

Change the password of the Postgres user (optional):

sudo -u postgres -i
psql postgres
rm .psql_history

Add the following to /etc/sysctl.conf:

kernel.shmmax = 268435456

Change the following lines in /etc/postgresql/8.4/main/postgresql.conf:

shared_buffers = 128MB
checkpoint_segments = 20
maintenance_work_mem = 256MB
autovacuum = off

In Kubuntu 10.04 and later, it may be necessary to uncomment the latter 3 lines (remove the hash sign # from the beginning of the line).

Reboot for the shared memory settings (shmmax) to take effect. Check with:

sysctl -a | grep shmmax

Create the GIS database and change its owner (to you).

sudo -u postgres -i
   createuser your_username
   createdb -O your_username gis
   createlang plpgsql gis
   psql -d gis -f /usr/share/postgresql/8.4/contrib/_int.sql
   psql -d gis -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
   psql -d gis
      ALTER TABLE geometry_columns OWNER TO your_username;
      ALTER TABLE spatial_ref_sys OWNER TO your_username;

Then you need to define the reference coordinate system by downloading:

and execute it using:

psql -d gis -f 900913.sql

Now download a map from and import it into the database using the following command:

osm2pgsql planet-nl-090221.osm.gz

Note that you need at least 1Gb of free RAM for this. If you have less, or if the command fails to allocate enough space, then use the -s option, and, if needed, the -C option. Then, however, you will need lots of disk space. In my case 6Gb was not enough, and that was just the map of the Netherlands... From the help info:

-s|--slim Store temporary data in the database. This greatly reduces the RAM usage but is much slower.
-C|--cache Only for slim mode: Use upto this many MB for caching nodes. Default is 800.

Start and quit gpsdrive, just in order to create its configuration directory. Then use the following commands to create a waypoint file if it does not exist and remove a config file before running gpsdrive in order to enable mapnik mode:

touch ~/.gpsdrive/way.txt
rm ~/.gpsdrive/osm.xml

Start gpsdrive. Enable mapnik mode and position mode. Click on the map to move it. Use the horizontal slider or Shift-LeftMB/Shift-RightMB to zoom in/out. When using gpsdrive for the first time, the cursor may be at a spot somewhere off the map. If this is the case, zoom out until you see a map and zoom into it.

Setting up the GPS device

If it is a USB device, its path will be something like /dev/ttyUSB0. If it is Bluetooth, make sure you have bluez-utils installed:

aptitude install bluez-utils

Then use the following command to find the address of your Bluetooth GPS device:

hcitool scan

Then connect it to /dev/rfcomm0:

rfcomm connect /dev/rfcomm0 xx:xx:xx:xx:xx:xx

Replace the x'es by the address of your GPS device. Test it using:

cat /dev/rfcomm0

You should see some coordinates passing by. Press Ctrl-C to quit. Now start gpsd:

gpsd /dev/rfcomm0

If you start gpsdrive now, it should find the GPS device.