Victor Houston


WebService::BorisBikes - A very simple web service to wrap around the live Barclays cycle hire availibility data from the Transport for London website.

To use this module, please register and create an account at transport for london first.

and always follow the usage guidelines ..


version 0.14


    use WebService::BorisBikes;

    my %params = ( 
        refresh_rate    => 120,    ## seconds
        debug_filename  => '/tmp/tflcycledata.xml',   
    my $BB = WebService::BorisBikes->new( \%params );



Returns a WebService::BorisBikes object. Accepts a hashref with possible keys of refresh_rate & debug_filename.

The refresh rate specifies in seconds how often to update station information. Refresh is performed automatically if needed after calling one of the public methods.

The debug_filename specifies the absolute position of a local London Cycle Scheme XML feed and is used for testing and debugging.


Returns a WebService::BorisBikes::Station object of the given id

    my $Station = $BB->get_station_by_id(533);


Returns an hashref with keys being the station_id and values being a WebService::BorisBikes::Station object.

    my $rh_stations = $BB->get_all_stations();


Returns the distance in meters between two station id's.

    my $meters = $BB->get_meters_distance_between_two_stations(566,547);


Accepts a hashref, where the keys must contain 'distance' in meters and one of the following ..

  1. latlong => A comma delimited string of a valid latitude and longitude

        my $rhh_stations = $BB->get_stations_nearby( 
            { 'distance' => 200, latlong => '52.521,-0.102' }
  2. postcode => A valid UK postcode (in greater London).

        my $rhh_stations = $BB->get_stations_nearby( 
            { 'distance' => 200, postcode => 'EC1M 5RF' }

If you do populate both latlong and postcode params, the latlong will be used, and the postcode ignored.

Returns a hashref with the keys being station_ids and values being ...

    'distance' => in meters from the postcode/latlong argument 
    'obj' => the WebService::BorisBikes::Station object.  

For example:

   '246' => {
               'obj' => bless( {
                   'id'           => '246'
                   'nbEmptyDocks' => '39',
               }, 'WebService::BorisBikes::Station' ),
               'distance' => '248.45237388466'


Accepts the same parameters as get_stations_nearby, but returns an arrayref of station ids, ordered by distance from.

my $ra_stations = $BB->get_station_ids_nearby_order_by_distance_from ({ postcode => 'EC1M 5RF', });


Search for station by their name attribute with case insensitive matching. Returns a hashref, keys being station id and values being WebService::BorisBikes::Station object.

    my $rh_stations = $BB->get_stations_by_name('holland park');



Accepts latitude, longitude and distance parameters finds the stations within range.


Populates $self->{stations} hashref. The key being the station_id, and the value is a WebService::BorisBikes:Station object.

   $self->{stations}->{1} = WebService::BorisBikes::Station


Returns true if our station data has become stale. Returns false otherwise.


If $self->{debug_filename} is not set, station data will be retrieved from the tfl website using LWP::Simple.

Otherwise, station data will be slurped from a downloaded xml file in the absolute location of $self->{debug_filename}.

Returns an hashref of station data hashes, after setting $self->{epoch_since_last_refresh}.


Return true if coordinate arguments are within a bounding box roughly the size of greater London.


Returns the distance in meters between a WebService::BorisBikes::Station object and WGS84 coordinates.


Uses GIS::Distance::Lite to calculate the distance in meters between two WGS84 coordinates, (Haversine formula).


Accepts the same hashref as WebService::BorisBikes::get_stations_nearby() and returns a latitude and longitude.


Returns true if parameters latitude is a float between -180 and 180 and longitude is a float between -90 and 90.