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!)

5 comments:

  1. Great thoughts you got there, believe I may possibly try just some of it throughout my daily life.

    Used Bikes

    ReplyDelete
  2. Is there a way to get Melbourne's station data in xml format like the other BIXI city?

    ReplyDelete
  3. This is like one of the tips..Chafing and rash caused by bike shorts is a common problem for cyclists. Read how other cyclists avoid rashes and chafing or share tips and strategies of your own.Bikes Brisbane

    ReplyDelete
  4. There's a "brisbane" in there now - e.g. http://www.citycycle.com.au/service/stationdetails/brisbane/52 (available bikes, free capacity, total capacity, ticket)

    http://api.citybik.es/citycycle.json has all the station data live. I don't know how that works. I can't imagine that they grab all 149 URLs every time you visit their site. Just replace with "melbourne" for Melbourne. Right now in Melbourne, there are 476 bikes available and a total of 903 bikes and free spots; in Brisbane last night there were 1361 bikes available and a total of 2934 bikes and free spots.

    ReplyDelete
  5. Melbourne data is at http://www.melbournebikeshare.com.au/stationmap/data

    ReplyDelete