diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-11-11 15:44:58 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-11-11 15:44:58 -0800 |
commit | 24ea1e9c67515f441982e8cabf69aefa81d130d7 (patch) | |
tree | 769cbb25689c1b2b084ea73be6ee74c8b80d23b8 | |
parent | 62f7ec11d72aeb4edbf4d6063ed3059912c7545a (diff) | |
download | subsurface-24ea1e9c67515f441982e8cabf69aefa81d130d7.tar.gz |
Location service: only store gps fix after certain time or distance
This should be configurable in the preferences at some point.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-mobile/gpslocation.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/qt-mobile/gpslocation.cpp b/qt-mobile/gpslocation.cpp index eb0f15292..d9132f28e 100644 --- a/qt-mobile/gpslocation.cpp +++ b/qt-mobile/gpslocation.cpp @@ -35,17 +35,30 @@ void GpsLocation::serviceEnable(bool toggle) } } +#define MINTIME 600 +#define MINDIST 200 + void GpsLocation::newPosition(QGeoPositionInfo pos) { + time_t lastTime; + QGeoCoordinate lastCoord; QString msg("received new position %1"); status(qPrintable(msg.arg(pos.coordinate().toString()))); geoSettings.beginGroup("locations"); int nr = geoSettings.value("count", 0).toInt(); - geoSettings.setValue("count", nr + 1); - geoSettings.setValue(QString("gpsFix%1_time").arg(nr), pos.timestamp().toTime_t()); - geoSettings.setValue(QString("gpsFix%1_lat").arg(nr), rint(pos.coordinate().latitude() * 1000000)); - geoSettings.setValue(QString("gpsFix%1_lon").arg(nr), rint(pos.coordinate().longitude() * 1000000)); - geoSettings.sync(); + if (nr) { + lastCoord.setLatitude(geoSettings.value(QString("gpsFix%1_lat").arg(nr)).toInt() / 1000000.0); + lastCoord.setLongitude(geoSettings.value(QString("gpsFix%1_lon").arg(nr)).toInt() / 1000000.0); + time_t lastTime = geoSettings.value(QString("gpsFix%1_time").arg(nr)).toULongLong(); + } + // if we have no record stored or if at least 10 minutes have passed or we moved at least 200m + if (!nr || pos.timestamp().toTime_t() > lastTime + MINTIME || lastCoord.distanceTo(pos.coordinate()) > MINDIST) { + geoSettings.setValue("count", nr + 1); + geoSettings.setValue(QString("gpsFix%1_time").arg(nr), pos.timestamp().toTime_t()); + geoSettings.setValue(QString("gpsFix%1_lat").arg(nr), rint(pos.coordinate().latitude() * 1000000)); + geoSettings.setValue(QString("gpsFix%1_lon").arg(nr), rint(pos.coordinate().longitude() * 1000000)); + geoSettings.sync(); + } } void GpsLocation::updateTimeout() |