Deep thoughts and Long Bike rides.
I have been tracking my bike rides for the past few years. These are mainly commuter miles with a few longer bike tours and weekend rides. I have adopted a few apps over the years, but I always liked Google MyTracks the best due to the fact that it gave me access to my stats and a map of my ride.
In the past, I could sync my data with my Google Drive account, and then view a spreadsheet of all of my rides, their stats, and a link to the route on a custom google map. This export was discontinued May 2013.
The current export format is a 5000 line KML file, riddled with markups and tag I don’t need. Where where my stats? Why can’t I aggregate my rides? I was pissed… Until I learned how to parse XML with Processing.
There were several problems with these KML files:
- A ton of markup info only the app or Google Maps cares about.
- Every damn coordinate was wrapped in its own tag, formatted with spaces… no array, no commas.
<gx:coord>-73.964595 40.675743 2.0</gx:coord>
- All of the good stats were in one tag, named <description> in a format that looked like JSON’s evil half baked cousin.
<description><![CDATA[Created by Google My Tracks on Android.
Name: West Side Ride Activity type: cycling Description: - Total distance: 48.65 km (30.2 mi) Total time: 2:56:52 Moving time: 2:46:59 Average speed: 16.50 km/h (10.3 mi/h) Average moving speed: 17.48 km/h (10.9 mi/h) Max speed: 45.90 km/h (28.5 mi/h) Average pace: 3.64 min/km (5.9 min/mi) Average moving pace: 3.43 min/km (5.5 min/mi) Fastest pace: 1.31 min/km (2.1 min/mi) Max elevation: 38 m (126 ft) Min elevation: -49 m (-161 ft) Elevation gain: 925 m (3035 ft) Max grade: 21 % Min grade: -27 % Recorded: 7/13/2013 7:05AM ]]>
Its my Data. Give it Back.
Well, unlike before, the app is giving me all of the data. But its formatted in such a way, its a real pain to use/plug in to any other program. I created a tool for bike riders who use MyTracks. This tool cleans up all the crap, and outputs nice clean GeoJSON to be used however they see fit. I also give them an HTML file to upload along with their JSON file to their server for a quick aggregated visualization.
Ride. Sync. Repeat.
- Download the processing sketch/tool here: DOWNLOAD ME
- Sync your MyTracks data with your Google Drive Account.
- Download all KML Files from the MyTracks folder in Drive and unzip.
- Drag and Drop all KML files into the DATA folder of the Processing sketch.
- Run the sketch, click in the sketch window, and press any key to save out a full JSON file. *If you don’t click and keyPress, the entire file will not write, and you will not have all of your data in a usable format!
- For a quick web visualization tool, upload your ride.json file along with the index.html file to a folder on your server and explore.
- Add any additional KML files to the data folder and run whenever you need to update your json file.