April 11, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

[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

 Signature 

Qt 4.7.3
Symbian OS v9.4 / Symbian^1, S60 5th Edition
on N97

9 replies

April 11, 2012

mlong mlong
Mad Scientist
1517 posts

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.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 11, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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.

 Signature 

Qt 4.7.3
Symbian OS v9.4 / Symbian^1, S60 5th Edition
on N97

April 11, 2012

mlong mlong
Mad Scientist
1517 posts

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.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 11, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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.

 Signature 

Qt 4.7.3
Symbian OS v9.4 / Symbian^1, S60 5th Edition
on N97

April 11, 2012

mlong mlong
Mad Scientist
1517 posts

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.”

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 11, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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.

 Signature 

Qt 4.7.3
Symbian OS v9.4 / Symbian^1, S60 5th Edition
on N97

April 11, 2012

mlong mlong
Mad Scientist
1517 posts

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.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 11, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

Ok, then I know what to do. Thank you.

 Signature 

Qt 4.7.3
Symbian OS v9.4 / Symbian^1, S60 5th Edition
on N97

April 11, 2012

mlong mlong
Mad Scientist
1517 posts

You’re welcome! Good luck!

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

 
  ‹‹ [SOLVED] What C++ equivalent has the QML point type?      adding objects to the “Map” with addMapObject ››

You must log in to post a reply. Not a member yet? Register here!