When I first published Every street in Amherst, several people asked me how I was generating the map data.
I expect other tools to do this exist, but I thought it would be nice to share, so I cleaned mine up a bit. A bit. It's still rough around the edges, but I'm not likely to improve it further.
You must configure gpxgoogle with a small
XML file in your home directory:
<config> <title>Google Maps GPS Track</title> <key>YOUR GOOGLE MAPS KEY</key> <width>540px</width> <height>540px</height> <units>mi</units> <colinear-threshold>0.0001</colinear-threshold> <icon>var icon = new GIcon(); icon.image = "http://www.example.com/images/x.png"; icon.shadow = "http://www.example.com/images/xshadow.png"; icon.iconSize = new GSize(3, 3); icon.shadowSize = new GSize(3, 3); icon.iconAnchor = new GPoint(1, 1); icon.infoWindowAnchor = new GPoint(2, 0);</icon> </config>
The configuration parameters are:
This will be used as the title of the generated HTML page.
This is your Google Maps key.
The width of the map.
The height of the map.
The units that you wish to use for displayed track data. You can specify “
mi” (miles), “
km” (kilometers), “
ft” (feet), or “
I've tried reasonably hard to make the calculations accurate, but of course they're not. They don't account for irregularities in the terrain, inaccuracy in the GPS, or the limitations of the floating point library.
In an effort to reduce the number of points on the map, gpxgoogle removes “colinear” points. These calculations treat the map as completely flat and the latitudes and longitudes as rectangular coordinates. This is wrong, of course, but for the distances in a typical track, I don't think the errors are significant.
Anyway, if the discrepancy between the point that is exactly colinear between two points and the actual position of the point in between is less than this threshold, the middle point is discarded. Empirically, a value of 0.0001 seems to work pretty well.
icon” and initializes it as appropriate for a Google Maps
Obvious improvements and open questions
As I said, I'm probably not going to do much more with gpxgoogle in the short term. But when (or if), I find the time, there are a few obvious improvements to be made.
Support the configuration parameters as command line options.
It'd be nice to be able to generate Yahoo maps too.
These maps don't work in PDF at all. Can anything be done about that?
If you decide to pursue any of these improvements, or any others, please let me know. Whether you do or not, share and enjoy!
[Update 21 June 2006: Not using version 2 of the Google Maps API was clearly short-sighted. Now updated. But not (yet) using any of its new features.]
[Update 12 July 2006: It appears that GPX tracks don't always include a timestamp for each point, as I'd expected. That caused a division by zero error, which I've now fixed.]