If you want to catch a tram in Melbourne then you need a Myki, despite the fact you can’t buy one or top it up onboard the tram. In 2017 The Age highlighted the difficulty this can pose for intending tram passengers, in an article on myki “dead zones” - tram stops where the nearest place to top up your myki is at least a kilometre away. Coincidently I started work on an almost identical project years ago but never finished it, so what better time to polish it off?

Using the Public Transport Victoria API

Back in March 2014 Public Transport Victoria finally opened up the application program interface (API) which powers their mobile apps, so I decided to have a play around with it.

With the mobile landscape already littered with hundreds of different trip planning apps, I decided to build something slightly different - something to point out how the lack of ticket purchase options onboard trams was wasting the time of the intending passengers.

The API allows programmers to access all kinds of data - tram routes and Myki retailers being two of them, so I built an app that caters for two use cases:

  • you're at home, work, or a friend's house - and you've discovered that you don't have a Myki on hand. Where is the nearest place to buy a new one, and how far will this detour take compared to purchasing a ticket onboard the tram?
  • you've just stepped onto a tram and discovered that you don't have any credit left on your Myki. How far will you have to walk to top up, and then where can you get back on your way?

The end result is ‘walki’ - a small app that works on any device with a web browser.

The logic in the app is as follows:

  1. Show the user their current location,
  2. Calculate distance to nearest tram stop,
  3. Calculate distance to nearest Myki retailer,
  4. Calculate distance from Myki retailer back to nearest tram stop,
  5. Plot the walking routes on a map,
  6. Compare the distances for each,
  7. And finally, show the user much further they have to walk thanks to the lack of ticket sales onboard trams.

Simple?

You can see it for yourself at https://wongm.com/walki/, or using these examples.

Technology

The app itself isn’t anything revolutionary from a technology standpoint.

In the backend I’m using boring old PHP to gather tram stop and myki retailer locations through calls to the PTV API, with the resulting data being mashed around in Javascript until they are drawn out on a pretty map.

The frontend code is static HTML files with a smattering of jQuery Mobile (‘state of the art’ for 2014? :-P) over the top, with the maps being drawn using the Google Maps JavaScript API v3.

The files are all hosted on my vanilla Apache web server, and you can find the source code on GitHub.