#!env python import gps file = '/tmp/nmea.kml' session = gps.gps(host="localhost", port="2947") session.stream(flags=gps.WATCH_JSON) for report in session: if report['class'] == 'TPV': latitude = report['lat'] longitude = report['lon'] altitude = report['alt'] speed_in = report['speed'] heading = report['track'] speed = int(speed_in * 1.852) range = ( ( speed / 100 ) * 350 ) + 650 tilt = ( ( speed / 120 ) * 43 ) + 30 if speed < 10: range = 200 tilt = 30 heading = 0 output = """ %s km/h ^ %s %s %s %s %s %s,%s,%s """ % (speed,longitude,latitude,range,tilt,heading,longitude,latitude,altitude) f=open(file, 'w') f.write(output) f.close() del session