View Single Post
jedi's Avatar
Posts: 1,411 | Thanked: 1,330 times | Joined on Jan 2010 @ Tatooine
#6
This is my script, based on the 'complete example'.

It waits for the GPS lock to be < 500 meters, then exists printing the lattitude, longitude and accuracy.

You could run this in a loop and 'record' the info using:
$ script.sh > logfile.txt
Code:
#!/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()
__________________
May the source be with you.
 

The Following 3 Users Say Thank You to jedi For This Useful Post: