aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-01 17:21:30 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-01 17:26:18 -0800
commit14a09689a421a32e812094b5fb99f33b99443266 (patch)
tree0943b9d37e725dd1f30bf33bd3155a4449898409
parent66cd83a70fcf315f639355eb191c57ca749b7eb4 (diff)
downloadsubsurface-14a09689a421a32e812094b5fb99f33b99443266.tar.gz
Location service: get the current position
If we have a fix that is fewer than 5 minutes old, take it, otherwise trigger an update. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--subsurface-core/gpslocation.cpp23
-rw-r--r--subsurface-core/gpslocation.h1
2 files changed, 24 insertions, 0 deletions
diff --git a/subsurface-core/gpslocation.cpp b/subsurface-core/gpslocation.cpp
index 5fe637137..9019f59c7 100644
--- a/subsurface-core/gpslocation.cpp
+++ b/subsurface-core/gpslocation.cpp
@@ -89,6 +89,29 @@ void GpsLocation::serviceEnable(bool toggle)
}
}
+QString GpsLocation::currentPosition()
+{
+ if (!hasLocationsSource())
+ return tr("Unknown GPS location");
+ int nr = geoSettings->value("count", 0).toInt();
+ if (nr) {
+ qDebug() << "last fix at" << geoSettings->value(QString("gpsFix%1_time").arg(nr - 1)).toULongLong() <<
+ "right now" << QDateTime::currentMSecsSinceEpoch() / 1000;
+ if (geoSettings->value(QString("gpsFix%1_time").arg(nr - 1)).toULongLong() + 300 > QDateTime::currentMSecsSinceEpoch() / 1000) {
+ QString gpsString = printGPSCoords(geoSettings->value(QString("gpsFix%1_lat").arg(nr - 1)).toInt(),
+ geoSettings->value(QString("gpsFix%1_lon").arg(nr - 1)).toInt());
+ qDebug() << "returning last position" << gpsString;
+ return gpsString;
+ }
+ }
+ qDebug() << "requesting new GPS position";
+ m_GpsSource->requestUpdate();
+ // ok, we need to get the current position and somehow in the callback update the location in the QML UI
+ // punting right now
+ waitingForPosition = true;
+ return QString("waiting for the next gps location");
+}
+
void GpsLocation::newPosition(QGeoPositionInfo pos)
{
time_t lastTime;
diff --git a/subsurface-core/gpslocation.h b/subsurface-core/gpslocation.h
index 0adcfdc29..94706f611 100644
--- a/subsurface-core/gpslocation.h
+++ b/subsurface-core/gpslocation.h
@@ -20,6 +20,7 @@ public:
int getGpsNum() const;
QString getUserid(QString user, QString passwd);
bool hasLocationsSource();
+ QString currentPosition();
private:
QGeoPositionInfo lastPos;