1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP [PHP] Generate POI files for GPS devices from website data ...

Discussion in 'Web Development' started by Gonzoide, Jul 29, 2014.

  1. Gonzoide

    Gonzoide New Member

    Hi all,

    On my diving website, a specific page indicates all diving spots we use. In order to simplify my members' life, I've created a small functionality to export those spots into POI files supported by most famous brands of GPS : Tomtom, Garmin, Magellan, Google Map, Navman, Mio, and possibly others

    I'm not sure this code will be useful to anybody, but it doesn't hurt to propose it here :)

    Each piece of code below will handle a specific file format completely : invoking it will directly propose to download a file containg all GPS points found in a database. It is assumed that point name, longitude and latitude can be obtained via a MySQL query

    For clarity I'll put one format per post. PHP code is simple for educational purpose :)
     
    Last edited: Jul 29, 2014
    Mildju and Dawn like this.
  2. Gonzoide

    Gonzoide New Member

    OV2 file for Tomtom

    <?php
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"filename.ov2\"");

    /* set your MySQL query here */

    while ($data = /* process result set */ ) {
    $name = $data['name'];
    $longitude = $data['longitude'];
    $latitude = $data['latitude'];

    $TT = chr(0x02).pack("V",strlen($name)+14).pack("V",round($longitude*100000)).pack("V",round($latitude*100000)).$name.chr(0x00);

    echo $TT;
    }
    ?>
     
  3. Gonzoide

    Gonzoide New Member

    KML file for Google Earth / Map

    <?php
    header("Content-type: application/vnd.google-earth.kml+xml");
    header("Content-Disposition: attachment; filename=\"filename.kml\"");

    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

    ?>
    <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
    <Document>
    <name>Plongeurs Masqués</name>
    <Style id="sn_ylw-pushpin">
    <IconStyle>
    <scale>1.1</scale>
    <Icon>
    <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
    </Icon>
    <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
    </IconStyle>
    </Style>
    <StyleMap id="msn_ylw-pushpin">
    <Pair>
    <key>normal</key>
    <styleUrl>#sn_ylw-pushpin</styleUrl>
    </Pair>
    <Pair>
    <key>highlight</key>
    <styleUrl>#sh_ylw-pushpin</styleUrl>
    </Pair>
    </StyleMap>
    <Style id="sh_ylw-pushpin">
    <IconStyle>
    <scale>1.3</scale>
    <Icon>
    <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
    </Icon>
    <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
    </IconStyle>
    </Style>
    <?



    /* set your MySQL query here */

    while ($data = /* process result set */ ) {
    $name = $data['name'];
    $longitude = $data['longitude'];
    $latitude = $data['latitude'];
    ?>

    <Placemark>
    <name><?= $name ?></name>
    <LookAt>
    <longitude><?= $longitude ?></longitude>
    <latitude><?= $latitude ?></latitude>
    <altitude>0</altitude>
    <range>1000</range>
    <tilt>0</tilt>
    <heading>0</heading>
    <altitudeMode>relativeToGround</altitudeMode>
    </LookAt>
    <styleUrl>#msn_ylw-pushpin</styleUrl>
    <Point>
    <coordinates><?= $longitude ?>,<?= $latitude ?>,0</coordinates>
    </Point>
    </Placemark>
    <?php
    }
    ?>
    </Document>
    </kml>
     
  4. Gonzoide

    Gonzoide New Member

    Format CSV (Navman, Garmin), CSV (Mio), RTE (Navigon, Magellan, Garmin)

    This one is a little bit special : formats are very similar, so same code handles them all ... by changing the value of variable "type" you may choose which format

    1 => CSV (Navma, Garmin)
    2 => CSV (Mio)
    3 => RTE (Navigon, Magellan, Garmin)

    This is included in the file, as a parsing of $_GET

    <?php
    header("Content-type: application/octet-stream");

    @require_once("dbaccess.php");
    @require_once("security.php");
    @require_once("database.php");

    $type=1;

    if (isset($_GET) && isset($_GET['type'])) {
    $type=$_GET['type'];
    }

    $file = "filename";

    if ($type == 1) {
    // Garmin, Navman

    $file = $file.".csv";
    } else if ($type == 2) {
    // MIO
    $file = $file.".csv";
    } else if ($type == 3) {
    // Navigon
    $file = $file.".rte";
    }

    header("Content-Disposition: attachment; filename=\"".$file."\"");

    /* set your MySQL query here */

    while ($data = /* process result set */) {
    $name = $data['name'];
    $longitude = $data['longitude'];
    $latitude = $data['latitude'];

    if ($type == 1) {
    // Garmin, Navman

    $string = $longitude.", ".$latitude.", "."\"".$name."\"\n";
    } else if ($type == 2) {
    // MIO
    $string = "\"".$name."\"".", "."\"".$name."\", ".$longitude.", ".$latitude.",,,\n";
    } else if ($type == 3) {
    // Navigon
    $string = "[".$name."|][0][10]|||".$longitude."|".$latitude."\n";
    }

    echo $string;
    }
    ?>