“Let’s Create Software” Tutorial: Bus Routes Overlaid on Google Maps

The “Let’s Create Software” series covers the creation of small, complete software projects from start to finish. The entire process and code is explained to give beginner and intermediate programmers an idea of what it is like to not just program, but create an entire piece of software from scratch.

There’s a large PDF system map of all the Muni bus routes in San Francisco (as well as maps of the individual Muni routes). If I need to find directions, Google Maps’ mass transit instructions are fine. But sometimes I’d like to just browse all the routes throughout the city. However the large PDF is slow to render on my laptop (moreso on my phone). Scrolling the PDF also results in a lengthy wait for redrawing.

So I had the idea to use Google Maps’ API to draw out a map of all the Muni routes. This would have the benefit of the system map PDF but also be easier to load and navigate. I have no experience using the Google Maps API and am vaguely aware that there’s public data about Muni bus routes, but I’ll learn along the way.

The completed SF Muni Google Map.

To follow along with this tutorial, it helps to have a bit of Python or JavaScript knowledge, or know a little bit about programming. I’ve tried to keep this as straightforward as possible, even for non-programmers to roughly follow.

This project will involve writing a few “throw-away” scripts to parse and extract data, and my preferred language is Python. While I do all the scripts in Python 3 (note: Python 3 has some backwards incompatibilities with Python 2. My scripts might not run on Python 2), you can use whatever language you like. The final software will be done with JavaScript since it is a web page that uses the Google Maps API. (The final result is here: http://inventwithpython.com/sfmuni/

In general, by “throw-away” script I mean a script that is written in order to be run once to perform a task. Software such as Firefox or Angry Birds I want to keep around to run again and again, but a throw-away script I just need to automate a certain task. I’ll still keep this script; I won’t actually delete this script once I’ve run it, but I most likely won’t ever need it again.

A note to beginning programmers who might feel like this project might be too advanced for them: even though I have years of experience programming, I still made many mistakes and went down a few blind alleys while putting this code together. Although it looks like I just sat down and typed out this code, just remember that this tutorial is the polished outcome of quite a bit of tenacious work. Don’t be discouraged or intimidated, just keep at it!

Prior Art Search

The first part before we do any programming project is to see what else is already out there. It might be fun to reimplement something that’s already out there, but by looking at what other people have done, we can get ideas for what we might want to do. Or you might find the exact software you wanted is already made, and can save yourself the trouble.

Doing a few Google Searches, I see that there’s SF Live Bus, which gives a live feed of every bus’s position using the Google Maps API and the NextBus API. But it doesn’t show the routes on the maps like the system map does.

NextBus has outfitted the buses and trains of many municipal transit systems with GPS locators and provides a data feed of them. They also have an API that is well documented.

Other than that, I haven’t really found anything like what I want to do specifically.

Decide on Features (and Non-Features)

Here’s what I want the software to do:

  • Use Google Maps with all the usual navigation controls that it provides, but all the Muni routes are overlaid on top of it.
  • Also, have all the stops marked on the map.

Also, it’s important to come up with a list of features you will not have. It’s really easy to say, “Hey it’d be cool if it could do this…” and keep accumulating features and making the software more complicated. While good learning experiences for the programmer, half-finished projects are almost always useless for other people. Our system map software will not have:

  • Display current position of the buses.
  • Have bus predictions for the stops.
  • Offer directions between locations.

Page 1 of 7 | Next page