Discussion:
A python script feed gpsd to Google Earth
w***@aol.com
2011-06-15 09:57:08 UTC
Permalink
There is a python program feed GPS input from serial device to Google
Earth. With little tweak, it allows Google Earth connect to gpsd for
real-time gps tracking.

The orginal serial-reading python program together with a thorough
how-to can be found at
http://tjworld.net/wiki/Linux/Ubuntu/GoogleEarthPlusRealTimeGPS .
Substitute gegpsd.py with the attached python script, then open the
generated kml file in google earth, enjoy!

Tested on Debian Squeeze with Holux M-241
--
Chen Wei
~
Chen Wei
2011-06-15 10:33:22 UTC
Permalink
Post by w***@aol.com
Substitute gegpsd.py with the attached python script, then open the
try attach the file again...
--
Chen Wei
Chen Wei
2011-06-15 10:45:02 UTC
Permalink
Post by Chen Wei
Post by w***@aol.com
Substitute gegpsd.py with the attached python script, then open the
try attach the file again...
#--------- begin ---------------

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import gps


def main(gpsd_report):
'''http://code.google.com/apis/kml/documentation/kmlreference.html
for official kml document'''
kml_file = './Realtime_GPS.kml'
latitude = gpsd_report['lat']
longitude = gpsd_report['lon']
speed_in = gpsd_report['speed'] # meter/second
speed = speed_in * 3.6 # Km/h
heading = gpsd_report['track']
altitude = gpsd_report['alt']
time_in = gpsd_report['time'] # time since the Unix epoch UTC
time_str = time.strftime("%Y-%m-%d %H:%M:%S UTC", time.gmtime(time_in))
gerange = ((speed / 100) * 350) + 650
tilt = 0

if speed < 1:
gerange = 200
heading = 0

output = """<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
<name>%s km/h,heading %s</name>
<description>Realtime GPS feeding</description>
<LookAt>
<longitude>%s</longitude>
<latitude>%s</latitude>
</LookAt>
<Point>
<coordinates>%s,%s,%s</coordinates>
</Point>
</Placemark>
</kml>""" % (speed,heading,longitude,latitude,longitude,latitude,altitude)

status_line = '<{0}> Speed: {1:.2f} Km/h, Heading: {2:.0f}'.format(time_str,
speed, heading)
print status_line
f = open(kml_file, 'w')
f.write(output)
f.close()


if __name__ == "__main__":
session = gps.gps()
session.stream(gps.WATCH_ENABLE|gps.WATCH_NEWSTYLE)

try:
while True:
report = session.next()
if report['class'] == 'TPV':
main(report)
except StopIteration:
print 'GPSD has terminated'

#--------- end ---------------
--
Chen Wei
Eric Raymond
2011-06-23 19:49:15 UTC
Permalink
Post by w***@aol.com
There is a python program feed GPS input from serial device to Google
Earth. With little tweak, it allows Google Earth connect to gpsd for
real-time gps tracking.
The orginal serial-reading python program together with a thorough
how-to can be found at
http://tjworld.net/wiki/Linux/Ubuntu/GoogleEarthPlusRealTimeGPS .
Substitute gegpsd.py with the attached python script, then open the
generated kml file in google earth, enjoy!
Tested on Debian Squeeze with Holux M-241
This is rather interesting. I might want to add it to the clients we ship.
What is the "gerange" calculation supposed to be doing?
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
Loading...