diff options
-rw-r--r-- | subsurface-core/gpslocation.cpp | 23 | ||||
-rw-r--r-- | subsurface-core/gpslocation.h | 1 |
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; |