diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-11-11 10:52:52 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-11-11 12:37:40 -0800 |
commit | 12a6a8f2b3afe4c6376b874f609be933ed5dbe5c (patch) | |
tree | 806621df5324f625a078b0f35e7105ee274f6220 | |
parent | 136b87e7c00b79ba8ee316ecf66dbc326e78c823 (diff) | |
download | subsurface-12a6a8f2b3afe4c6376b874f609be933ed5dbe5c.tar.gz |
Location service: request position update
Mostly still just experimental code - now it tries to get an actual
position.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | gpslocation.cpp | 29 | ||||
-rw-r--r-- | gpslocation.h | 13 | ||||
-rw-r--r-- | subsurface-mobile-helper.cpp | 3 |
3 files changed, 41 insertions, 4 deletions
diff --git a/gpslocation.cpp b/gpslocation.cpp index 6725abfb9..da4734897 100644 --- a/gpslocation.cpp +++ b/gpslocation.cpp @@ -1,7 +1,32 @@ #include "gpslocation.h" +#include <QDebug> -GpsLocation::GpsLocation() -{ +GpsLocation::GpsLocation(QObject *parent) +{ + QGeoPositionInfoSource *gpsSource = QGeoPositionInfoSource::createDefaultSource(parent); + if (gpsSource != 0) { + qDebug() << "have position source" << gpsSource->sourceName(); + connect(gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(newPosition(QGeoPositionInfo))); + connect(gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout())); + lastPos = gpsSource->lastKnownPosition(); + gpsSource->requestUpdate(1000); + QGeoCoordinate lastCoord = lastPos.coordinate(); + if (lastCoord.isValid()) { + qDebug() << lastCoord.toString(); + } else { + qDebug() << "invalid last position"; + } + } else { + qDebug() << "don't have GPS source"; + } +} +void GpsLocation::newPosition(QGeoPositionInfo pos) +{ + qDebug() << "received new position" << pos.coordinate().toString(); } +void GpsLocation::updateTimeout() +{ + qDebug() << "request to get new position timed out"; +} diff --git a/gpslocation.h b/gpslocation.h index 68f574bd7..8e26fd25e 100644 --- a/gpslocation.h +++ b/gpslocation.h @@ -1,16 +1,25 @@ #ifndef GPSLOCATION_H #define GPSLOCATION_H +#include <QObject> #include <QGeoCoordinate> +#include <QGeoPositionInfoSource> +#include <QGeoPositionInfo> -class GpsLocation +class GpsLocation : QObject { + Q_OBJECT public: - GpsLocation(); + GpsLocation(QObject *parent); + +private: + QGeoPositionInfo lastPos; signals: public slots: + void newPosition(QGeoPositionInfo pos); + void updateTimeout(); }; #endif // GPSLOCATION_H diff --git a/subsurface-mobile-helper.cpp b/subsurface-mobile-helper.cpp index e982760f8..0643ae9e0 100644 --- a/subsurface-mobile-helper.cpp +++ b/subsurface-mobile-helper.cpp @@ -18,6 +18,8 @@ #include "qt-mobile/qmlmanager.h" #include "qt-models/divelistmodel.h" #include "qt-mobile/qmlprofile.h" +#include "gpslocation.h" +GpsLocation *locationProvider; QObject *qqWindowObject = NULL; @@ -52,6 +54,7 @@ void run_ui() qml_window->setHeight(1200); qml_window->setWidth(800); #endif + locationProvider = new GpsLocation(qml_window); qml_window->show(); qApp->exec(); } |