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 if device.fix: if device.fix[1] & location.GPS_DEVICE_LATLONG_SET: print "lat = %f, long = %f" % device.fix[4:6] #data.stop() def on_stop(control, data): print "quitting" data.quit() def start_location(data): data.start() return False def get_speed(device, data): if not device: return if device.fix: if device.fix[1] & location.GPS_DEVICE_SPEED_SET: print "lat = %f, Speed %s Km/h" % device.fix[speed] on_changed #data.stop() #i = 0 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) #while i < 2: #device.connect("changed", get_speed, control) device.connect("changed", on_changed, control) #print i, # i = i + 1 control.connect("gpsd-stopped", on_stop, loop) gobject.idle_add(start_location, control) loop.run()