Home | Cookies Policy | Search | A-Z | 3s | Conventions | FAQs | Help 
Dove's Guide Cover Picture Dove's Guide for Church Bell Ringers

PHP code for generating ov2 binary files

During the course of developing the Dove website, I received several requests to make location data available for import into TomTom software by providing .ov2 binary POI files. TomTom already distribute an executable to perform an ASCII to binary conversion for creating these files but I wanted to generate the binary file directly, without the end-user having to perform a conversion.

Below is a PHP class to create such files, along with sufficient additional code to provide a working example. Please feel free to reuse this code, whilst retaining a credit to me.

<?php

$poiFile 
= new ov2file();
$poiFile->filename "MyPOIs.ov2";

$poiFile->add_POI(51.51387, -0.09940"London, S Paul's Cath");
$poiFile->add_POI(51.51758, -0.10645"London, Holborn");
$poiFile->add_POI(51.51872, -0.09920"London, Smithfield");

setHeaders($poiFile->filename);
echo 
$poiFile->content;

class 
ov2file
{
  
// ov2file
  // (c) 2006 Sid Baldwin
  // Created on 06-Feb-2006
  
var $content "";
  var 
$filename "default.ov2";
  function 
add_POI($lat,$long,$text) {
    
$this -> content .= "\x02";
    
$this -> content .= pack("I"14 strlen($text));
    
$this -> content .= pack("i"round($long*100000));
    
$this -> content .= pack("i"round($lat*100000));
    
$this -> content .= $text;
    
$this -> content .= "\x00";
    return;
  }
}

function 
setHeaders($filename){
  
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past
  
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
  
header("Content-type: application/x-download");
  
header("Content-Disposition: attachment; filename={$filename}");
  
header("Content-Transfer-Encoding: binary");
}

?>

Sid Baldwin, Feb 2006

 
Programming: Sid Baldwin
Admin Login
Dove data file last modified 24 Jan 2020 16:29 GMT
Page last modified 19 Nov 2017 11:48 GMT
Page served 25 Jan 2020 06:22 GMT
Page executed in 0.001 seconds