TTC subway map using Google Maps

I spent a little time this weekend playing with the Google Maps API and creating an overlay of the TTC subway. Not surprisingly, creating the station markers and route lines was easy. The most difficult part, however, was obtaining a list of subway stations and their addresses in a text format for easy extraction.

Translating the subway station addresses into GPoint objects was a little difficult given that there appears to be no free geocoding service for Canadian addresses. However, Google Maps can work as a geocoder, albeit a somewhat slow one, sometimes taking several seconds to produce a result. If you have access to a Unix command-line, you can make use of the following script:

#!/bin/sh
wget -q -O- http://maps.google.com?q=\\
`echo $1 | tr " " "+"` | sed -n -e \\
"s/.*<point lat=\"\\([^\"]*\\)\" lng=\"\\([^\"]*\\)\".*/new GPoint( \\2, \\1 )/p"

If I have one beef with the API, it’s with the GIcon class and the requirement to set the icon shadow, the icon and shadow sizes and the anchor point. A shadow should not be required and image sizes can be inferred. However, the icon will not display if any of these properties are not set.

Update: I have since added a clickable list of subway stations to the map.

Update: Now any Google Map can contain the TTC subway map.

  1. Ghosty

    June 21, 2006 at 10:01 pm

    There actually is a free geocoding service for Canada, you can use either http://www.geocoder.ca

    or you can actually use Yahoo’s API, the key is to NOT provide the postal code, and simply the country code following the address.

    I prefer yahoo as the limitations of use are far less than geocoder.ca however with such a small amount of stations

  2. Chad Thomas

    August 24, 2005 at 2:41 pm

    Great work! I found it because I was looking for the addresses in text format. It would be more than helpful if you could tell me where you got them or send me the file.

    There is a small mistake on the University line. It does not go to the St. George and Spadina stations.

  3. Patrick Dinnen

    July 22, 2005 at 10:11 am

    Hi Ian
    Nice work with the TTC map, I was thinking of trying that myself.

    Just wanted to let you know that there is now a free geocoding service for Canadian addresses. Check out http://www.geocoder.ca/

  4. TTC subway map upgraded to Toronto Transit Map - crazed monkey

    November 11, 2006 at 12:50 am

    […] About a year ago I played around with the Google Maps API and created a map containing the TTC subway system. It wasn’t intended to be all that useful as the TTC’s own map contains much more information. Still, that didn’t stop my map from rising to the top of the Google rankings for TTC-related searches, resulting in hundreds of visits. A few people sent me emails and comments thanking me for making the map, and it even got a mention in the print version of the June 2006 issue of HUB. I didn’t see much reason for the fuss as the map could have been so much better. […]

  5. Alton

    November 13, 2006 at 11:24 am

    I was looking at your java script referenced above and I noticed a slight problem. CM_rtLinePoints has six points, but CM_rtLineHtml has only five labels. It seems Kennedy at 2455 Eglinton Ave. East is not present. Is there a reason?

  6. Ian Stevens

    November 13, 2006 at 1:01 pm

    I probably didn’t include Kennedy in the HTML for the RT line because it exists in the HTML for the Bloor-Danforth line, and I didn’t want to create duplicate markers. It’s in the points for the RT line probably because of an oversight.

  7. Serguei

    November 21, 2006 at 12:54 am

    (please delete my previous post, it was for a wrong article)
    Nice stuff! We need something similar in Montreal, our STM morons still sitting on their ass with
    PDF files too..
    Check out my map: http://mtlmap.com – just started, only subway for now, pretty simple.
    BTW, how long it took you to draw this image?!!! Must be weeks and weeks… :)

  8. Stef

    February 20, 2007 at 8:17 pm

    This is the most useful tool in getting around Toronto that I’ve encountered in the 18 months I have been here! Thank you sooo much!

  9. RandomRussianDude

    April 11, 2007 at 1:33 pm

    hax!
    This is pretty cool stuff, man. Maybe TTC will order you another custom map. This time for the busdrivers. With all the Tim Hortons locations on it, so these a$$hole$ know where to stop by on the route. =)
    (You know how annoying this is when you’re in a hurry and they do it? lol)

  10. Javed

    August 28, 2007 at 10:50 am

    This is great! One more item if you can add that will make it perfect is having to/from field for calculating distances/directions from/to subway stations and bus routes.

  11. phillip

    November 20, 2007 at 9:46 pm

    Hi, Thanks for the map. I must suggest that the area name list be unicoloured and tighter margins, allowing the map to fill a greater field with mapquest-like appearance. This shoud be linked on the TTC homepage.

  12. Tom Chalker

    May 29, 2008 at 1:20 pm

    Nice work.
    One small improvement, if you have time:
    Could you print the complete street address of the stop in the balloons, including the Postal Code?
    If I paste the existing partial address you display into a GoogleMaps ‘get directions to’ pane, I get a lot of potential choices for this destination but I don’t know which one is correct.

    Thx

  13. Sanjeev

    August 19, 2008 at 12:33 am

    Nice work. I wish i had come across it earlier but am pretty sure i will make use of it.
    cheers
    S