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.