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