-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRetroLocation.cpp
97 lines (85 loc) · 1.99 KB
/
QRetroLocation.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "QRetroCommon.h"
#include "QRetroLocation.h"
QRetroLocation::QRetroLocation(QObject* parent)
{
setParent(parent);
#if QRETRO_HAVE_LOCATION
m_InfoSource = QGeoPositionInfoSource::createDefaultSource(this);
if (m_InfoSource)
{
connect(m_InfoSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
}
#endif
}
QRetroLocation::~QRetroLocation()
{
#if QRETRO_HAVE_LOCATION
delete m_InfoSource;
#endif
}
bool QRetroLocation::getPosition(double *lat, double *lon,
double *horiz_accuracy, double *vert_accuracy, bool quiet)
{
if (!m_Updated)
*lat = *lon = *horiz_accuracy = *vert_accuracy = 0;
else
{
*lat = m_Latitude;
*lon = m_Longitude;
*horiz_accuracy = m_HorizontalAccuracy;
*vert_accuracy = m_VerticalAccuracy;
if (!quiet)
m_Updated = false;
}
return true;
}
#if QRETRO_HAVE_LOCATION
void QRetroLocation::positionUpdated(const QGeoPositionInfo &update)
{
m_Latitude = update.coordinate().latitude();
m_Longitude = update.coordinate().longitude();
m_HorizontalAccuracy = update.attribute(QGeoPositionInfo::HorizontalAccuracy);
m_VerticalAccuracy = update.attribute(QGeoPositionInfo::VerticalAccuracy);
m_Updated = true;
}
#endif
void QRetroLocation::setPosition(double lat, double lon, double horiz_accuracy,
double vert_accuracy)
{
m_Latitude = lat;
m_Longitude = lon;
m_HorizontalAccuracy = horiz_accuracy;
m_VerticalAccuracy = vert_accuracy;
m_Updated = true;
m_SetManually = true;
}
void QRetroLocation::setUpdateInterval(int ms)
{
#if QRETRO_HAVE_LOCATION
if (m_InfoSource)
m_InfoSource->setUpdateInterval(ms);
#else
Q_UNUSED(ms)
#endif
}
bool QRetroLocation::startUpdates(void)
{
#if QRETRO_HAVE_LOCATION
if (m_InfoSource)
m_InfoSource->startUpdates();
return true;
#else
return false;
#endif
}
bool QRetroLocation::stopUpdates(void)
{
#if QRETRO_HAVE_LOCATION
if (m_InfoSource)
m_InfoSource->stopUpdates();
return true;
#else
return false;
#endif
}