Guest User

SRM live data TDF2011 for Google Earth

a guest
Jul 18th, 2011
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.     Transmogrify data used by http://data.srmlive.de/TDF/ for use in Google Earth
  5.  
  6.     Version 2.0 by Mike Beggs 2011-07-18
  7.  
  8.     Usage:
  9.    
  10.         0. Place script on a server that has PHP
  11.         1. Add 'Network Link' in Google Earth with address of script in 'Link' field
  12.         2. Set Refresh interval of Network Link
  13.         3. Enjoy
  14. */
  15.  
  16. //header('Content-Type: application/vnd.google-earth.kml+xml');
  17. header('Content-Type: text/xml');
  18.  
  19. ?><?xml version="1.0" encoding="UTF-8"?>
  20. <kml xmlns="http://www.opengis.net/kml/2.2">
  21. <Document>
  22. <name>TDF GPS Data</name>
  23. <Style id="sh_bike">
  24. <IconStyle>
  25.   <scale>1.0</scale>
  26.   <Icon>
  27.     <href>http://maps.google.com/mapfiles/kml/paddle/pink-blank.png</href>
  28.   </Icon>
  29.   <hotSpot x="0.5" y="0" xunits="fraction" yunits="fraction" />
  30. </IconStyle>
  31. <LabelStyle>
  32.  <color>ff00ffff</color>
  33.  <scale>0.8</scale>
  34. </LabelStyle>
  35. </Style>
  36. <?php
  37.  
  38. $xml = simplexml_load_file('http://data.srmlive.de/TDF/drivers/gps1.xml');
  39. $riderdata = explode("\n", file_get_contents('http://data.srmlive.de/TDF/drivers/rider_1.txt'));
  40.  
  41. $rider_team = array(
  42.     'Jeremy Roy' => 'FDJ',
  43.     'Daniel Oss' => 'LIQ',
  44.     'Paolo Borghini' => 'LIQ',
  45.     'Brian Vandborg' => 'SBS',
  46.     'Christian Knees' => 'SKY',
  47.     'Julien El Fares' => 'COF',
  48.     'Romain Zingle' => 'COF',
  49.     'Mickael Buffaz' => 'COF',
  50.     'Andrey Zeits' => 'AST',
  51.     'Thomas Vaitkus' => 'AST',
  52.     'Markel Irizar' => 'RSH',
  53.     'Brent Bookwalter' => 'BMC',
  54.     'Michael Schaer' => 'BMC'
  55. );
  56.  
  57. $rider = 0;
  58.  
  59. foreach($xml->marker as $marker) {
  60.  
  61.     if(($marker->attributes()->lat != 0) || ($marker->attributes()->lng != 0)){ // Exclude if rider is located in the Gulf of Guinea
  62. ?>
  63. <Placemark>
  64.     <name><?php
  65.        
  66.         $data = explode(';', trim($riderdata[$rider]));
  67.        
  68.         $name = ''.$marker->attributes()->name;
  69.        
  70.         echo $name.' #'.$data[0];
  71.        
  72.         if(array_key_exists($name, $rider_team)) {
  73.             echo ' ('.$rider_team[$name].')';
  74.         }
  75.  
  76.         // Note: I created this version of the script while these data fields were dead, so they may be labelled wrong.
  77.         if($data[1] != '-') echo ' '.$data[1].'k'; // Speed
  78.         if($data[2] != '-') echo ' '.$data[2].'r'; // Cadence
  79.         if($data[3] != '-') echo ' ♥'.$data[3].''; // Heart rate
  80.         if($data[4] != '-') echo ' '.$data[4].'W'; // Power output
  81.    
  82.     ?></name>
  83.     <styleUrl>#sh_bike</styleUrl>
  84.     <Point>
  85.         <coordinates><?php echo $marker->attributes()->lng.','.$marker->attributes()->lat?></coordinates>
  86.     </Point>
  87. </Placemark>
  88. <?php
  89.  
  90.         $rider++;
  91.     }
  92. }
  93.  
  94. ?>
  95. </Document>
  96. </kml>
Add Comment
Please, Sign In to add comment