2015-11-11 18:54:36 +00:00
|
|
|
#include "qt-mobile/gpslocation.h"
|
2015-11-11 19:16:59 +00:00
|
|
|
#include "qt-mobile/qmlmanager.h"
|
2015-11-11 18:52:52 +00:00
|
|
|
#include <QDebug>
|
2015-11-11 18:50:55 +00:00
|
|
|
|
|
|
|
|
2015-11-11 18:52:52 +00:00
|
|
|
GpsLocation::GpsLocation(QObject *parent)
|
|
|
|
{
|
2015-11-11 20:32:54 +00:00
|
|
|
gpsSource = QGeoPositionInfoSource::createDefaultSource(parent);
|
2015-11-11 18:52:52 +00:00
|
|
|
if (gpsSource != 0) {
|
2015-11-11 19:16:59 +00:00
|
|
|
QString msg = QString("have position source %1").arg(gpsSource->sourceName());
|
2015-11-11 18:52:52 +00:00
|
|
|
connect(gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(newPosition(QGeoPositionInfo)));
|
|
|
|
connect(gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
|
|
|
|
lastPos = gpsSource->lastKnownPosition();
|
2015-11-11 19:16:59 +00:00
|
|
|
gpsSource->startUpdates();
|
2015-11-11 18:52:52 +00:00
|
|
|
QGeoCoordinate lastCoord = lastPos.coordinate();
|
|
|
|
if (lastCoord.isValid()) {
|
2015-11-11 19:16:59 +00:00
|
|
|
status(msg + lastCoord.toString());
|
2015-11-11 18:52:52 +00:00
|
|
|
} else {
|
2015-11-11 19:16:59 +00:00
|
|
|
status(msg + "invalid last position");
|
2015-11-11 18:52:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-11-11 19:16:59 +00:00
|
|
|
status("don't have GPS source");
|
2015-11-11 18:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-11 20:34:56 +00:00
|
|
|
|
|
|
|
void GpsLocation::serviceEnable(bool toggle)
|
|
|
|
{
|
|
|
|
if (!gpsSource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (toggle) {
|
|
|
|
gpsSource->startUpdates();
|
|
|
|
status("Starting Subsurface GPS service");
|
|
|
|
} else {
|
|
|
|
gpsSource->stopUpdates();
|
|
|
|
status("Stopping Subsurface GPS service");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 18:52:52 +00:00
|
|
|
void GpsLocation::newPosition(QGeoPositionInfo pos)
|
|
|
|
{
|
2015-11-11 19:16:59 +00:00
|
|
|
QString msg("received new position %1");
|
|
|
|
status(qPrintable(msg.arg(pos.coordinate().toString())));
|
2015-11-11 18:50:55 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 18:52:52 +00:00
|
|
|
void GpsLocation::updateTimeout()
|
|
|
|
{
|
2015-11-11 19:16:59 +00:00
|
|
|
status("request to get new position timed out");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpsLocation::status(QString msg)
|
|
|
|
{
|
|
|
|
qDebug() << msg;
|
|
|
|
qmlUiShowMessage(qPrintable(msg));
|
2015-11-11 18:52:52 +00:00
|
|
|
}
|