#!/usr/bin/python import location import gobject def on_error(control, error, data): print "location error: %d... quitting" % error data.quit() def on_changed(device, data): if not device: return #Uncomment line below to show progress... #print "Accuracy: ",device.fix[6]," Lat/Long: ",device.fix[4:6] if not device.fix[6] == device.fix[6]: return if device.fix[6] > 50000: return if device.fix: if device.fix[1] & location.GPS_DEVICE_LATLONG_SET: print device.fix[4]," ",device.fix[5]," ",device.fix[6] data.stop() def on_stop(control, data): data.quit() def start_location(data): data.start() return False loop = gobject.MainLoop() control = location.GPSDControl.get_default() device = location.GPSDevice() control.set_properties(preferred_method=location.METHOD_USER_SELECTED, preferred_interval=location.INTERVAL_DEFAULT) control.connect("error-verbose", on_error, loop) device.connect("changed", on_changed, control) control.connect("gpsd-stopped", on_stop, loop) gobject.idle_add(start_location, control) loop.run()