Nearly 2 months ago, I got a GPS tracker. I discovered its antenna is sufficiently sensitive to work in my pocket so I took it on my Saturday morning bike ride. Back home, I was able to retrieve data from the tracker in various formats. What can I do with this data? Find the total distance I rode, of course!
I am lazy 😉 so I decided to use the Kompass track file since it’s only a CSV text file (I should have used the GPX file format but parsing XML is still more difficult for me than a plain text file). With a rather simple Python script, I was able to store all the latitudes and longitudes in a collection of objects. But, hey, how do I compute the distance from longitudes and latitudes?
To find the distance between 2 points of which you only have latitudes and longitudes, there is a formula given by Dr. Math for example. To use this formula, you need the Earth radius. Since the Earth is not a perfect sphere, I’ll use an approximation of its radius at a given geodetic latitude (based on the latitude of the start point of my bike ride). With these two formulas, you can find the total distance of a GPS track (of course, it will still be an approximation).
So, this morning, I rode 14.5km at a mean speed of 27.5km/h (it’s only the beginning …).
But I want more! I want to see where I went on a real map! No problem … For that purpose, I’ll use Google Maps. In the same Python script, I define two GPoint: one for the start and one for the end of the trip (I also wanted to show the time of these points on the map). The path I did is just a GPolyline. The map is centered in the middle between the start and end points. The following elements can easily be customized: zoom level, path color, width and transparency. I added a parameter to be able to downsample data (in case of large data set). So, finally, I succeeded to draw this kind of map …
The map is included in a frame. If you can’t see it, here is the link to the map. Enjoy!
Now the most interesting part: here (22ko) is the Python code, all the graphic elements, the HTML template page, an example of track file from my GPS tracker and the map below (as usual, everything is under the GNU GPL licence).
Of course, you already have some similar services on the web. But only the GPS Visualizer is better than my solution, imho. In all other services I found (Gmaps Pedometer, MapMyRun et Walk Jog Run), you have to draw your path yourself: this is not precise and can be a pain if you have to enter many points. And, with my solution, I am happy I was able to solve this problem 🙂
All that to tell you that I started to ride my bike this year 🙂