|
|
2010-05-14
, 07:21
|
|
Posts: 13 |
Thanked: 9 times |
Joined on Dec 2009
@ Espoo, Finland
|
#2
|
|
|
2010-05-14
, 18:15
|
|
|
Posts: 1,411 |
Thanked: 1,330 times |
Joined on Jan 2010
@ Tatooine
|
#3
|
In the on_change function, do not call data.stop(). Then you will still get updates on the location. What I do is to compare the new location to the old one, and if it's close enough determine that the GPS has given as accurate location as it can and then stop.
I guess we're talking about this block of code:def on_changed(device, data):
if not device:
return
if device.fix:
if device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
print "%f %f" % device.fix[4:6]
data.stop()
|
|
2010-05-14
, 20:05
|
|
|
Posts: 1,411 |
Thanked: 1,330 times |
Joined on Jan 2010
@ Tatooine
|
#4
|
|
|
2010-05-15
, 11:02
|
|
Posts: 13 |
Thanked: 9 times |
Joined on Dec 2009
@ Espoo, Finland
|
#5
|
| The Following User Says Thank You to Hukka For This Useful Post: | ||
|
|
2010-05-15
, 12:06
|
|
Posts: 20 |
Thanked: 16 times |
Joined on Jan 2010
@ Norway
|
#6
|
| The Following User Says Thank You to rcastberg For This Useful Post: | ||
|
|
2010-05-17
, 21:16
|
|
|
Posts: 1,411 |
Thanked: 1,330 times |
Joined on Jan 2010
@ Tatooine
|
#7
|

#!/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()
|
|
2010-05-24
, 09:39
|
|
Posts: 13 |
Thanked: 9 times |
Joined on Dec 2009
@ Espoo, Finland
|
#8
|
|
|
2010-05-25
, 07:15
|
|
|
Posts: 1,411 |
Thanked: 1,330 times |
Joined on Jan 2010
@ Tatooine
|
#9
|
I certainly hope there is not. I don't want any apps draining the battery without me knowing about it.
|
|
2010-05-25
, 07:23
|
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#10
|
Next question - is it possible to stop the GPS icon appearing in the notification area?
| The Following User Says Thank You to nicolai For This Useful Post: | ||
But the signal is a long way off - and I was under the impression that if the GPS was on for longer, there was more chance of the location being accurate.
So my question is, how could I adapt this script to make it wait 1 minute? or 5 minutes etc before returning the location? Would this make the location more accurate?
I'm code a bit in PHP but am finding Python a bit baffling...
Any help appreciated.
Thanks