Sunday, October 3, 2010

How I got data for Brisbane's CityCycle system.

The CityCycle system is based on a REST API which uses XML to display data.

The data can easily be parsed in languages such as PHP using the simplexml function.

CityCycle only uses 2 URLs to get information,

The first one is: https://abo-brisbane.cyclocity.fr/service/carto
Which provides you with an XML list of all stations, the station number, longitude and latitude and if the station is open or not.

The other URL is:
https://abo-brisbane.cyclocity.fr/service/stationdetails/X

Where "X" is the station number. (eg. stationdetails/52 which will display data for the Brunswick St Mall / Wickham St station)

Here is some sample PHP code that I've used in my KML creation scripts:

<?php
// Sample script by Adrian Lodders (http://BikeShare.Tel, http://CycleHire.Tel, http://CityCycle.Tel)
$xml = simplexml_load_file('https://abo-brisbane.cyclocity.fr/service/carto') or die("Error: Unable to connect to the City Cycle Station Feed.");
$i = 0;
foreach ($xml->markers->marker as $item){
$name = $xml->markers->marker[$i]->attributes()->address;
echo "$name<br/>";
$i++;
}
?>

The script above will call the XML list of all stations, then display all names of each station until its gone through the whole list.

With this, its possible to use the station and its number in conjunction with an AJAX script to get the individual station data (rather then calling it all at once).

Anyway, I hope this helps.
Adrian Lodders

(ps. I didn’t test to see if the script above works cause its 12:21AM and daylight savings is about to kick in!)