Over the years I’ve been using TramTracker on my ancient Nokia mobile phone, until December 2013 when Yarra Trams updated the web version of the service, and rendered it unusable on older devices.
Unlike other public transport operators, Yarra Trams actually took my feedback on board and released an updated web version of TramTracker a month later, but unfortunately for me, they were not enough to make it work with my ancient WAP only phone.
As a result, I took inspiration from my recent experiments with PTV’s new API, and came up with a simple website to give access to TramTracker data.
Called ‘Jake Junior: TramTracker for Dumbphones’, you can give it a go at http://jakejunior.wongm.com/.
TramTracker first appeared in Melbourne way back in December 2006, with only two ways of accessing tram arrival information: voice or SMS reply. However usage of the service didn’t take off until 2009, when an incredibly well designed iPhone app was released, providing a much more convenient way to find tram stops and arrival times.
Since then additional methods of access have been provided – a mobile friendly website for non-iPhone devices, a ‘webPID’ for desktop computers in 2009, and an Android app in October 2012. Third-party developers have also built their own apps for the TramTracker service – the most interesting one I’ve found so far is TramFinder for Pebble watches!
One thing these third-party apps have in common is their source of tram arrival data – a public API found at http://ws.tramtracker.com.au/pidsservice/pids.asmx. This API isn’t the easiest thing to play around with because it follows the SOAP specification for webservices – a horrible tarball of XML requests being sent back and forth between devices.
Messing around with SOAP isn’t my idea of fun, so I put building my own ‘simple’ version of TramTracker on the backburner, until I discovered that the new version of the TramTracker website was actually using RESTful calls to a backend service that was returning JSON
I was unsure if that version of the API was actually designed for the public to consume, so I posed the question on Twitter, only for the original developer of the TramTracker iPhone app to give me an answer:
— Rob Amos (@bok_) March 14, 2014
With that in mind, I spent a few hours cobbling together some PHP code, with ‘Jake Junior’ being the end result.
How it works
Internally ‘Jake Junior’ is just a single PHP file – you can find the source code at https://github.com/wongm/jake-junior.
Stop information and tram arrival times are retrieved using two hits to the TramTracker API: unfortunately it doesn’t combine the two types of data into a single method.
To get the name and direction of a tram stop, I used to the ‘GetStopInformation’ endpoint:
And for the arrival times, the ‘GetNextPredictionsForStop’ endpoint:
By the way – TramTracker ID 1234 is on route 1 in South Melbourne!
Once I had the results of the two API calls as a JSON string, I was able to deserialise the data, do some simple maths to convert the JSON timestamp into a minutes until arrival figure, and then output it all as HTML.
You can play around with the end result at http://jakejunior.wongm.com.
If you are wondering about the ‘Jake Junior’ name – the official TramTracker mascot is dog named Jake.