Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpp-position.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page location-positioning-cpp.html
6
7
\title Positioning (C++)
8
9
\brief The Location Positioning API enables location positioning by means of
10
GPS or an NMEA data source.
11
12
\section1 Positioning
13
14
The Positioning component of the Qt Location API is about the geographical
15
position, size, and address of some place. Positioning contains a
16
\l QGeoCoordinate class, containing latitude, longitude and altitude in meters.
17
\l QGeoLocation contains a \l QGeoCoordinate plus address and size information
18
(a bounding box) so that positions can be more than mathematical points.
19
Movement into or out of the defined bounding box areas can be monitored. The API
20
also allows the developer to control the source of the positional information
21
as well.
22
23
Location data involves a precisely specified position on the Earth's
24
surface \unicode {0x2014} as provided by a latitude-longitude coordinate
25
\unicode {0x2014} along with associated data, such as:
26
27
\list
28
\li The date and time at which the position was reported
29
\li The velocity of the device that reported the position
30
\li The altitude of the reported position (height above sea level)
31
\li The bearing of the device in degrees, relative to true north
32
\endlist
33
34
This data can be extracted through a variety of methods. One of the most
35
well known methods of positioning is GPS (Global Positioning System), a
36
publicly available system that uses radiowave signals received from
37
Earth-orbiting satellites to calculate the precise position and time of
38
the receiver. Another popular method is 'Cell Identifier Positioning', which uses
39
the cell identifier of the cell site that is currently serving the receiving
40
device to calculate its approximate location. These and other positioning
41
methods can all be used with the Location API; the only requirement for a
42
location data source within the API is that it provides a
43
latitude-longitude coordinate with a date/time value, with the option of
44
providing the other attributes listed above.
45
46
47
Location data sources are created by subclassing \l QGeoPositionInfoSource and
48
providing \l QGeoPositionInfo objects through the
49
\l {QGeoPositionInfoSource::positionUpdated()} signal. Clients that require
50
location data can connect to the
51
\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal and
52
call \l{QGeoPositionInfoSource::startUpdates()}{startUpdates()} or
53
\l{QGeoPositionInfoSource::requestUpdate()}{requestUpdate()} to trigger the
54
distribution of location data. The location data distribution can be stopped by
55
calling the \l {QGeoPositionInfoSource::stopUpdates()}{stopUpdates()} function.
56
57
A default position source may be available on some platforms. Call
58
\l {QGeoPositionInfoSource::createDefaultSource()} to create an instance of the
59
default position source. The method returns \c nullptr if no default source is
60
available for the platform.
61
62
If a problem occurs with access to the information source then an
63
\l {QGeoPositionInfoSource::errorOccurred()}{errorOccurred()} signal is emitted.
64
65
The \l QGeoAreaMonitorSource class enables client applications to be notified
66
when the receiving device has moved into or out of a particular area, as
67
specified by a coordinate and radius. If the platform provides built-in support
68
for area monitoring, the \l {QGeoAreaMonitorSource::createDefaultSource()}
69
method returns an instance of the default area monitor.
70
71
Satellite information can also be distributed through the
72
\l QGeoSatelliteInfoSource class. Call
73
\l {QGeoSatelliteInfoSource::createDefaultSource()} to create an instance of the
74
default satellite data source for the platform if one is available.
75
Alternatively, clients can subclass it to provide a custom satellite data
76
source.
77
78
79
80
\section2 Requesting Location Data from Data Sources
81
82
To receive data from a source, connect to its
83
\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal,
84
then call either \l{QGeoPositionInfoSource::startUpdates()}{startUpdates()}
85
or \l{QGeoPositionInfoSource::requestUpdate()}{requestUpdate()} to begin.
86
87
Here is an example of a client that receives data from the default location
88
data source, as returned by \l {QGeoPositionInfoSource::createDefaultSource()}:
89
90
\code
91
class MyClass : public QObject
92
{
93
Q_OBJECT
94
public:
95
MyClass(QObject *parent = 0)
96
: QObject(parent)
97
{
98
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
99
if (source) {
100
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
101
this, SLOT(positionUpdated(QGeoPositionInfo)));
102
source->startUpdates();
103
}
104
}
105
106
private slots:
107
void positionUpdated(const QGeoPositionInfo &info)
108
{
109
qDebug() << "Position updated:" << info;
110
}
111
};
112
113
\endcode
114
115
\section2 Controlling Aspects of Data Sources
116
117
The \l {QGeoPositionInfoSource::setUpdateInterval()} method can be used to
118
control the rate at which position updates are received. For example, if
119
the client application only requires updates once every 30 seconds, it can
120
call \c setUpdateInterval(30000). If no update interval is set, or
121
\l {QGeoPositionInfoSource::}{setUpdateInterval()} is called with a value of 0,
122
the source uses a default interval or some other internal logic to determine
123
when updates should be provided.
124
125
\l {QGeoPositionInfoSource::setPreferredPositioningMethods()} enables client
126
applications to request that a certain type of positioning method be used.
127
For example, if the application prefers to use only satellite positioning,
128
which offers fairly precise outdoor positioning but can be a heavy user of
129
power resources, it can call this method with the
130
\l {QGeoPositionInfoSource::SatellitePositioningMethods} value. However, this
131
method should only be used in specialized client applications; in most
132
cases, the default positioning methods should not be changed, as a source
133
may internally use a variety of positioning methods that can be useful to
134
the application.
135
136
\section2 NMEA Data
137
138
\l {http://en.wikipedia.org/wiki/NMEA_0183}{NMEA} is a common text-based
139
protocol for specifying navigational data. For convenience, the
140
\l QNmeaPositionInfoSource is provided to enable client applications to read
141
and distribute NMEA data in either real-time mode (for example, when
142
streaming from a GPS device) or simulation mode (for example, when reading
143
from a NMEA log file). In simulation mode, the source will emit updates
144
according to the time stamp of each NMEA sentence to produce a "replay"
145
of the recorded data.
146
147
Generally, the capabilities provided by the default position source as
148
returned by \l {QGeoPositionInfoSource::createDefaultSource()}, along with the
149
\l QNmeaPositionInfoSource class, are sufficient for retrieving location
150
data. However, in some cases developers may wish to write their own custom
151
location data source.
152
153
The \l {Log File Position Source (C++)} example demonstrates how to subclass
154
\l QGeoPositionInfoSource to create a custom positioning source.
155
156
\section1 Examples
157
158
\section3 \b{Log File Position Source Example}
159
160
The \l{Log File Position Source (C++)}{Log File Position Source} Example demonstrates
161
how to subclass \l QGeoPositionInfoSource to create a custom positioning source.
162
163
\section3 \b{Weather Info Example}
164
165
The \l{Weather Info} example shows how to use the user's current
166
position to retrieve local content from a web service in a C++ plugin for QML.
167
168
\section1 Positioning Classes
169
170
\annotatedlist QtPositioning-positioning
171
172
*/
qtpositioning
src
positioning
doc
src
cpp-position.qdoc
Generated on Mon Mar 10 2025 01:10:56 for Qt by
1.13.2