Script: vg_proxy.php Download a GPS track and return it in a JSON format License: GNU General Public License This file is part of VisuGps VisuGps is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. VisuGps is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VisuGps; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Copyright (c) 2007-2008 Victor Berchet, <http://www.victorb.fr> */ header('Content-type: text/plain; charset=ISO-8859-1'); header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); require 'vg_cfg.inc.php'; require 'vg_tracks.php'; $track = array(); if (isset($_GET['track'])) { $track = MakeTrack($_GET['track']); } else { if (isset($_GET['trackid'])) { $track = GetDatabaseTrack(intval($_GET['trackid'])); } } echo "var trackData = JSON.parse(" . @json_encode($track) . ');';
function generate_kml_task($task, $delay, $utcOffset) { $file = "<?xml version='1.0' encoding='UTF-8'?>\n" . "<kml xmlns='http://earth.google.com/kml/2.2'>\n" . "<Document>\n" . "<Folder>\n" . "<Style id='picon'>\n" . " <IconStyle>\n" . " <Icon>\n" . " <href>http://victorb.fr/visugps/img/picon.png</href>\n" . " <hotSpot x='50' y='0' xunits='pixels' yunits='pixels'/>\n" . " </Icon>\n" . " </IconStyle>\n" . "</Style>\n" . "<name>Pilots</name>\n"; $ids = GetTaskFlights($task, $utcOffset); $maxPilots = max(5, count($ids)); for ($i = 0; $i < count($ids); $i++) { $jsonTrack = GetDatabaseTrack($ids[$i], $delay, $utcOffset); $track = @json_decode($jsonTrack, true); $color = 'FF' . value2color($i, 0, $maxPilots); if (isset($track['nbTrackPt']) && $track['nbTrackPt'] > 5) { $file .= generate_kml_linestring($track['pilot'], $track, $color, 2); $file .= generate_kml_point($track['pilot'], end($track['lat']), end($track['lon']), end($track['elev'])); } } /* $file .= "</Folder><Folder><name>Turn points</name>\n" . "<Placemark>\n" . " <name>Start 12:30</name>\n" . " <Point>\n" . " <coordinates>\n" . " 6.456398, 44.013995, 3000\n" . " </coordinates>\n" . " </Point>\n" . "</Placemark>\n" . "<Placemark>\n" . " <name>B2</name>\n" . " <Point>\n" . " <coordinates>\n" . " 6.470938, 43.961758, 3000\n" . " </coordinates>\n" . " </Point>\n" . "</Placemark>\n" . "<Placemark>\n" . " <name>B3</name>\n" . " <Point>\n" . " <coordinates>\n" . " 6.443883, 44.047477, 3000\n" . " </coordinates>\n" . " </Point>\n" . "</Placemark>\n" . "<Placemark>\n" . " <name>B4</name>\n" . " <Point>\n" . " <coordinates>\n" . " 6.383936, 43.961208, 3000\n" . " </coordinates>\n" . " </Point>\n" . "</Placemark>\n" . "<Placemark>\n" . " <name>B5</name>\n" . " <Point>\n" . " <coordinates>\n" . " 6.557838, 43.944109, 3000\n" . " </coordinates>\n" . " </Point>\n" . "</Placemark>\n" . "<Placemark>\n" . " <name>Goal</name>\n" . " <Point>\n" . " <coordinates>\n" . " 6.510494, 43.958585, 3000\n" . " </coordinates>\n" . " </Point>\n" . "</Placemark>\n" . "</Folder>\n</Document>\n</kml>"; */ $file .= "</Folder>\n" . "</Document>\n" . "</kml>"; return $file; }