Created
April 12, 2011 22:04
-
-
Save dmongeau/916544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//ON INCLUS TOUTES LES VARIABLES NECESSAIRE A BIXI | |
//require_once ("../../path.inc.php"); | |
//////////////////////////////////////////////////////////////// | |
//ini_set(allow_url_fopen, 1); | |
function getAllStationsWithoutId(){ | |
$in="https://profil.bixi.ca/data/bikeStations.xml"; | |
$content= file_get_contents($in); | |
$xml=new SimpleXMLElement($content); | |
//Cr�ation d un tableau tres accessible | |
$myStationArray=array(); | |
foreach($xml as $key=>$station){ | |
//Variables utiles | |
$name=(string) $station->name; | |
$lat=(string) $station->lat; | |
$long=(string) $station->long; | |
$nbBikes=(string) $station->nbBikes; | |
$nbEmptyDocks=(string) $station->nbEmptyDocks; | |
$installed=(string) $station->installed; | |
$locked=(string) $station->locked; | |
$temporary=(string) $station->temporary; | |
$myStationArray[]= | |
array('name'=>$name,'lat'=>$lat,'long'=>$long,'nbBikes'=>$nbBikes,'nbEmptyDocks'=>$nbEmptyDocks,'installed'=>$installed,'locked'=>$locked,'temporary'=>$temporary); | |
} | |
return $myStationArray; | |
} | |
$allStation=getAllStationsWithoutId(); | |
//Creation du fichier | |
//Ecriture dans le fichier | |
$ch="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | |
$ch.="\n"; | |
$ch.="<kml xmlns=\"http://earth.google.com/kml/2.1\"> <Document>"; | |
$ch.="<name>Bixi</name> | |
"; | |
$ch.="\n"; | |
//Parcours des stations | |
foreach($allStation as $key=>$st){ | |
//Traitement des statuts | |
if($st['installed']=="true" and $st['locked']=="false" ){ | |
$ch.="<Placemark> | |
<name>".utf8_encode("V�lo").": ".$st['nbBikes']." - Ancrages :".$st['nbEmptyDocks']."</name> | |
<description>".$st['name']."</description>"; | |
$ch.="<Point><coordinates>".$st['long'].",".$st['lat']."</coordinates></Point> | |
</Placemark>"; | |
} | |
$ch.="\n"; | |
} | |
$ch.="\n"; | |
$ch.="</Document></kml>"; | |
$ch.="\n"; | |
$name="bixi-".time().".kml"; | |
header('Content-Type: application/vnd.google-earth.kml+xml'); | |
header('Content-Disposition: attachment; filename="'.$name.'"'); | |
echo $ch; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment