9 self.loop = gobject.MainLoop()
12 self.control = location.GPSDControl.get_default()
13 self.control.set_properties(preferred_method=location\
14 .METHOD_USER_SELECTED,
15 preferred_interval=location\
17 self.control.connect("error-verbose", self.on_error, self.loop)
18 self.control.connect("gpsd-stopped", self.on_stop, self.loop)
20 self.device = location.GPSDevice()
21 self.device.connect("changed", self.on_changed, self.control)
23 def update_location(self):
24 """ Run the loop and update lat and long """
26 gobject.idle_add(self.start_location, self.control)
29 def on_error(self, control, error, data):
31 print "location error: %d... quitting" % error
34 def on_changed(self, device, data):
35 """ Set long and lat """
39 # once fix is found and long, lat available set long lat
40 if device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
42 if self.fix_count > 1:
43 self.lat, self.long = device.fix[4:6]
46 def on_stop(self, control, data):
47 """ Stop the location service """
51 def start_location(self, data):
52 """ Start the location service """
58 """ Reset coordinates """
61 self.device.reset_last_known()