[solved] Getting the last known position from GPS
-
Hello,
I need the last known position from my GPS even if it is not turned on.
Viewranger is a program in which I can see my last known position even if the GPS receiver is turned off.
How to do so in QML, maybe with the PositionSource element ?
Thank you
-
You'll have to write some code to store your GPS fixes (either as they come in, or when your program exits) to a file, which you can then read in as your program starts next time. I'm not sure of a QML-native way to do this, but would be easy enough to do through a simple C++ class.
-
Your idea is, I think, the easiest and the one which is the least complicated.
I am not sure but I really think that these positions are already stored on my device.
In the example, I used Viewranger to see where I was when I turned off GPS but I don't remeber having run Viewranger when I turned GPS off. -
bq. I am not sure but I really think that these positions are already stored on my device.
They may be. But as far as I know, that's not a documented feature that can (or should) be relied upon.
-
Ok, but then, with your solution, I always have to keep my program running in the background with a timer to cyclically write the GPS coordinates in the file if they are !==NaN.
Then I think of adding my program to the system startup, but how to do so ?
Maybe a new topic would be appropiate to ask this. -
I don't think having your app running in the background is a good idea (especially considering battery drain, etc.)
You had said the "last known" value. That's different than "The current value of the GPS whether or not my app is running."
-
My idea was running my app always in the background and saving the GPS's coordinates in a text file if they are valid (that's what I meant with "!== NaN").
This app should work as a "helper" app.Then when my actual program is run and not GPS is turned on, it checks the file and gets the position.
But I think you are right that running the program in the background might harm the battery.
-
As I had stated previously, if it's a "good enough" solution, you could always save the last known coordinate that your app knew about as your app shuts down. You shouldn't need to save every position that comes in. Only the final one.
-
Ok, then I know what to do. Thank you.
-
You're welcome! Good luck!