Converting GPX to OV2 with PHP

Here’s how you can convert GPX to OV2 with PHP. This is necessary for example to GeoCachers who use TomTom navigators and want to have GeoCaches as POIs on the navigator.

Earlier work

There’s POIConverter, which manages lots of conversions, but is Windows only. There’s Convert POI, which is a web site, but it choked on my larger data sets.

Hence the need for something that works on my Mac and can handle more data. I program with PHP for a living, thus I’m using that.

The code

I found some PHP code for writing OV2 files on PCReview forums. After that the rest was easy:

$gpx = "9911360.gpx";
$pois = simplexml_load_file($gpx);

$file = "Geocache.ov2";
$fp = fopen($file, "w");

foreach ($pois->wpt as $wpt) {
	$lat = $wpt['lat'];
	$lon = $wpt['lon'];
	$des = $wpt->desc . " - " . $wpt->name;

	$lat = str_replace('.', '.', $lat);
	$lon = str_replace('.', '.', $lon);
	$des = str_replace('ä', 'a', $des);
	$des = str_replace('ö', 'o', $des);
	$des = str_replace('å', 'a', $des);

	echo $des . "\n";

	$TT = chr(0x02).pack("V",strlen($des)+14).pack("V",round($lon*100000)).pack("V",round($lat*100000)).$des.chr(0x00);
	@fwrite ($fp, "$TT");

That’s it. Put the name of the source file (a Pocket Query file from works well) in $gpx and run the program (you’ll need to have a PHP interpreter installed; OS X should come with one already installed). It’ll write the results in the Geocache.ov2 file, feel free to rename that. The code also cleans out Scandinavian letters from the descriptions, because they didn’t work and I don’t feel like solving how to make them work.

Installing the POIs

Geocache logoHow to get this on your TomTom navigator: connect the navigator to your computer, but don’t run the TomTom software. Open the navigator in Finder or Explorer and put the OV2 file to your map folder (in my case Scandinavia). If you include a 22×22 pixel BMP file that has the same name, that’ll be used as an icon. A suitable BMP is on this page. Make sure the file names are the same, sans the suffix, for the OV2 and the BMP file.

That’s it. Now when you start your navigator, GeoCaches will show up on your navigator map. You can also navigate to a particular cache from the navigate to POI menu. You can’t see any information about the caches on the map, so if you want to pop over to take a look, you’ll have to figure out which cache it is. Choosing ”Navigate to a nearby POI” from your navigator should help in that, or you can use a smartphone app to find nearby caches.


Sähköpostiosoitettasi ei julkaista. Pakolliset kentät on merkitty *

This site uses Akismet to reduce spam. Learn how your comment data is processed.