A few days ago, I decided to bike home from work (from Brussels to Leuven). Inspired by the "gefietst" blog en based upon the route here I made my adapted route to get to my home. The bike trip went well. Of course, I was wandering how long the bike trip was. Since I have a basic bike with no equipement to measure this I had to resort to the Google Maps info. I was almost sure that a webservice would exist that calculated the length of linesegments of Google Maps or from a KML file but after some searching I found no easy way to do this via the web. (If somebody would be aware of such a service, please drop me a line in the comments) Therefore, I decided to write a small Python script to calculate the lenght of all lines drawn on a Google Map. Just go to your map, click on "Link to this page", copy the URL and fill the URL in the Python script. Run the Python script and, bingo, you have the length in kilometers for every continuous linesegment. Here's the code:
The output of the above script is:
distance of fietsweg is 36.35 kilometer
Of course, this calculation is only an approximation since the trajectory is only an approximation (albeit a pretty good one) of the real route I followed and no heigth information is taken into account. Still I guess that its accurate upto a few kilometers. If somebody has a spare Bluetooth GPS receiver, you can always send me one ;-).
The calculation of the distance in kilometer between two points is based on the code in Ruby and the examples from the zips project a sourceforge. The coordinates of the linesegments are obtained from the KML file that Google Maps generates when appending &output=kml to the URL from 'link to this page'. The KML file is parsed using the Python minidom module. I hope that in the future Google will provide a "&output=jsonp&callback=calcfunc" so that a simple webpage with some Javascript can calculate the length. But that's for another programming project.