<?php
/*
Transmogrify data used by http://data.srmlive.de/TDF/ for use in Google Earth
Version 2.0 by Mike Beggs 2011-07-18
Usage:
0. Place script on a server that has PHP
1. Add 'Network Link' in Google Earth with address of script in 'Link' field
2. Set Refresh interval of Network Link
3. Enjoy
*/
//header('Content-Type: application/vnd.google-earth.kml+xml');
header('Content-Type: text/xml');
?><?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>TDF GPS Data</name>
<Style id="sh_bike">
<IconStyle>
<scale>1.0</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/paddle/pink-blank.png</href>
</Icon>
<hotSpot x="0.5" y="0" xunits="fraction" yunits="fraction" />
</IconStyle>
<LabelStyle>
<color>ff00ffff</color>
<scale>0.8</scale>
</LabelStyle>
</Style>
<?php
$xml = simplexml_load_file('http://data.srmlive.de/TDF/drivers/gps1.xml');
$riderdata = explode("\n", file_get_contents('http://data.srmlive.de/TDF/drivers/rider_1.txt'));
$rider_team = array(
'Jeremy Roy' => 'FDJ',
'Daniel Oss' => 'LIQ',
'Paolo Borghini' => 'LIQ',
'Brian Vandborg' => 'SBS',
'Christian Knees' => 'SKY',
'Julien El Fares' => 'COF',
'Romain Zingle' => 'COF',
'Mickael Buffaz' => 'COF',
'Andrey Zeits' => 'AST',
'Thomas Vaitkus' => 'AST',
'Markel Irizar' => 'RSH',
'Brent Bookwalter' => 'BMC',
'Michael Schaer' => 'BMC'
);
$rider = 0;
foreach($xml->marker as $marker) {
if(($marker->attributes()->lat != 0) || ($marker->attributes()->lng != 0)){ // Exclude if rider is located in the Gulf of Guinea
?>
<Placemark>
<name><?php
$data = explode(';', trim($riderdata[$rider]));
$name = ''.$marker->attributes()->name;
echo $name.' #'.$data[0];
if(array_key_exists($name, $rider_team)) {
echo ' ('.$rider_team[$name].')';
}
// Note: I created this version of the script while these data fields were dead, so they may be labelled wrong.
if($data[1] != '-') echo ' '.$data[1].'k'; // Speed
if($data[2] != '-') echo ' '.$data[2].'r'; // Cadence
if($data[3] != '-') echo ' ♥'.$data[3].''; // Heart rate
if($data[4] != '-') echo ' '.$data[4].'W'; // Power output
?></name>
<styleUrl>#sh_bike</styleUrl>
<Point>
<coordinates><?php echo $marker->attributes()->lng.','.$marker->attributes()->lat?></coordinates>
</Point>
</Placemark>
<?php
$rider++;
}
}
?>
</Document>
</kml>