![]() |
Python script for GPS location help appreciated
I've been using the example script from here:http://wiki.maemo.org/PyMaemo/Using_Location_API. It works fine - switching the GPS on momentarily and returning the long/lat of the GPS signal.
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 |
Re: Python script for GPS location help appreciated
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.
|
Re: Python script for GPS location help appreciated
Quote:
Thanks for your tantilizing clue :) I guess we're talking about this block of code: Code:
def on_changed(device, data): I'm still finding Python mind boggling! Thanks for your help :) |
Re: Python script for GPS location help appreciated
ah, so I needed to add 'import time' at the top, then 'time.sleep(30)' before the 'print %f...' line to make it wait 30 seconds...
That *seems* to give me a more accurate reading... i think..? |
Re: Python script for GPS location help appreciated
Well, the problem with hard timed reads is that the gps might not give you the data. What I mean is that you want to wait for 30 seconds for an update, but the gps gives you one after 25 seconds and 90 seconds (it happens if the device isn't moving at all).
So instead you might need to just save all the updates to a variable and then have a separate thread counting the timeouts and stopping the data loop, because after running loop.run() you are fully in asynchronous mode (that is, you couldn't say loop.run() then wait(30) and then data.stop()). But if the possibly longer timeouts don't matter to you (or you are constantly on the move) you could just save the current time when your program starts and then in "if device.fix" do "if datetime.datetime.now() > savedtime + datetime.timedelta(seconds=30)". |
Re: Python script for GPS location help appreciated
Alternativly check device.fix[6]
This gives eph, Horizontal position accuracy And wait for this to fall below a specified number. (Not sure what is a sensible limit) |
Re: Python script for GPS location help appreciated
Cool - I think I've made progress - thanks Hukka/rcastberg :)
For anyone interested, here's my script. It waits for the horizontal accuracy to be less than 500 meters, then exits printing the latitude, longitude and the horizontal accuracy. Code:
#!/usr/bin/python Next question - is it possible to stop the GPS icon appearing in the notification area? |
Re: Python script for GPS location help appreciated
I certainly hope there is not. I don't want any apps draining the battery without me knowing about it.
|
Re: Python script for GPS location help appreciated
Quote:
Anyone else with any constructive comments? |
Re: Python script for GPS location help appreciated
Quote:
and move this file temporarily somewhere else. nicolai |
All times are GMT. The time now is 22:48. |
vBulletin® Version 3.8.8