blob: fea313950bbeedaa4194c9e05277e7baa6ad797e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include "qt-mobile/gpslocation.h"
#include "qt-mobile/qmlmanager.h"
#include <QDebug>
GpsLocation::GpsLocation(QObject *parent)
{
gpsSource = QGeoPositionInfoSource::createDefaultSource(parent);
if (gpsSource != 0) {
QString msg = QString("have position source %1").arg(gpsSource->sourceName());
connect(gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(newPosition(QGeoPositionInfo)));
connect(gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
lastPos = gpsSource->lastKnownPosition();
gpsSource->startUpdates();
QGeoCoordinate lastCoord = lastPos.coordinate();
if (lastCoord.isValid()) {
status(msg + lastCoord.toString());
} else {
status(msg + "invalid last position");
}
} else {
status("don't have GPS source");
}
}
void GpsLocation::newPosition(QGeoPositionInfo pos)
{
QString msg("received new position %1");
status(qPrintable(msg.arg(pos.coordinate().toString())));
}
void GpsLocation::updateTimeout()
{
status("request to get new position timed out");
}
void GpsLocation::status(QString msg)
{
qDebug() << msg;
qmlUiShowMessage(qPrintable(msg));
}
|