Skip to content

Instantly share code, notes, and snippets.

@larsar
Forked from bluemaex/latitude.py
Created July 14, 2013 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsar/5996372 to your computer and use it in GitHub Desktop.
Save larsar/5996372 to your computer and use it in GitHub Desktop.
import os
import simplejson
import subprocess
import datetime
f = open('latitude.json', 'r')
locdata = simplejson.loads(f.read());
fd = open('latitude.gpx', 'w')
fd.write("""# <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1"><trk><name>Google Latitude Export</name><trkseg>""")
lastloc = None
for value in reversed(sorted(locdata['data']['items'])):
print value
#raise Exception('def');
if lastloc:
timedelta = (int(value['timestampMs']) - int(lastloc['timestampMs'])) / 1000 / 60
if timedelta > 10:
# no points for 10 Minutes, Start new Track
fd.write( "</trkseg><trkseg>")
fd.write( '<trkpt lat="%s" lon="%s">' % (value['latitude'], value['longitude']))
fd.write( '<time>%s</time></trkpt>' % str(datetime.datetime.fromtimestamp(int(value['timestampMs'])/1000)).replace(' ', 'T') + 'Z')
lastloc = value
fd.write( "</trkseg></trk></gpx>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment