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
qml-maps.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
\group qml-QtLocation5-maps
6
\title QML Maps Plugin
7
QML Support for the Qt Location API.
8
*/
9
10
11
/*!
12
\page qml-location5-maps.html
13
\title QML Maps
14
15
\brief Maps deals with maps, their contents and navigation.
16
17
\section1 Overview
18
19
The \l Map type allows the display of a map and placing objects within the map.
20
Various points of interest can be defined and added to the map for display.
21
Also the \l Map has features to control how the map is displayed. With the
22
Map item you can center the map, zoom, pinch and make the item flickable.
23
24
The places to be added to the map are
25
\l {Maps and Navigation (QML)#Putting Objects on a Map (Map Overlay Objects)}{MapItems}. The item's
26
position is defined by a \l [QtPositioning]{geoCoordinate} which includes
27
latitude, longitude and altitude. The item is then displayed automatically
28
after it is added to the \l Map.
29
30
\section2 Position on map
31
32
All position APIs are part of the \l {QtPositioning} module.
33
The basic piece of position information is the
34
\l [QtPositioning]{geoCoordinate}. A geoCoordinate encapsulates data for the
35
latitude, longitude and altitude of the location. Altitude is in meters. It
36
also has a method to determine distance to another geoCoordinate. The
37
\l [QtPositioning]{geoCoordinate} type may
38
also be held within a \l [QtPositioning]{Location} element, this will also have information
39
on a bounding box size to determine sufficient proximity to the location and a location address.
40
41
42
Here is an example of a client that uses a \l{PositionSource}{position source}
43
to center a \l{Map}{map} on the current position:
44
45
\code
46
import QtPositioning
47
import QtLocation
48
...
49
50
Rectangle {
51
52
Map {
53
id: map
54
// initialize map
55
...
56
}
57
58
PositionSource {
59
onPositionChanged: {
60
// center the map on the current position
61
map.center = position.coordinate
62
}
63
}
64
}
65
\endcode
66
67
\section2 Geocoding
68
69
\l {http://en.wikipedia.org/wiki/Geocoding}{Geocoding} is the derivation of
70
geographical coordinates (latitude and longitude) from other geographical references
71
to the locations. For example, this can be a street address. Reverse geocoding is also possible with
72
a street address being used to determine a geographical coordinate. Geocoding
73
is performed by using the \l [QML]{GeocodeModel} type.
74
75
The following code examples are a small part of the \c map component in the
76
\l {Map Viewer (QML)}{Map Viewer (QML)} example. The snippets
77
demonstrate the declaration of the \l GeocodeModel component.
78
79
In the snippet we see that the \l [QML]{GeocodeModel} contains the plugin
80
and two signal handlers. One for changes in status \l [QML]{GeocodeModel::status}{\c onStatusChanged} and
81
the other to update the centering of the Map object \l [QML]{GeocodeModel::locationsChanged}{\c onLocationsChanged}.
82
83
\snippet mapviewer/map/MapComponent.qml geocodemodel0
84
\codeline
85
\snippet mapviewer/map/MapComponent.qml geocodeview
86
87
The geocoding features are called from a higher level piece of code. In this
88
snippet we see an \l [QML]{Address} object filled with the desired parameters.
89
90
\snippet mapviewer/Main.qml geocode0
91
92
The \l [QML]{Address} is later used in a query for the \l GeocodeModel to
93
process and determine the geographical
94
\l [QtPositioning]{geoCoordinate}{coordinates}.
95
96
\snippet mapviewer/map/MapComponent.qml geocode1
97
98
99
\section2 Navigation
100
101
A very important function of the \l Map type is navigation
102
from one place to a destination with possible waypoints along the route. The
103
route will be divided up into a series of segments. At the end of each segment
104
is a vertex called a \e maneuver. The \e segments contain information about
105
the time and distance to the end of the segment. The \e maneuvers contain information
106
about what to do next, how to get onto the next segment, if there is one. So
107
a \e maneuver contains navigational information, for example "turn right now".
108
109
To find a suitable route we will need to use a \l RouteQuery to define the
110
selection criteria and adding any required waypoints.
111
The \l RouteModel should return a list of \l {routeSegment}s that defines the
112
route to the destination complete with navigation advice at the joins between
113
segments, called \l {routeManeuver}s
114
115
There are many options that you can add to the query to narrow the criteria.
116
The \l RouteQuery properties can include
117
118
\table 60%
119
\row
120
\li \l {RouteQuery::}{numberAlternativeRoutes}
121
\li The number of alternative routes
122
\row
123
\li \l {RouteQuery::}{travelModes}
124
\li Travel modes
125
\row
126
\li \l {RouteQuery::}{routeOptimizations}
127
\li Required route optimizations
128
\row
129
\li \l {RouteQuery::}{segmentDetail}
130
\li Level of detail in segments
131
\row
132
\li \l {RouteQuery::}{maneuverDetail}
133
\li Level of detail in maneuvers between segments
134
\row
135
\li \l {RouteQuery::}{waypoints}
136
\li A list of waypoints
137
\row
138
\li \l {RouteQuery::}{excludedAreas}
139
\li A list of excluded areas that the route must not cross
140
\row
141
\li \l {RouteQuery::}{featureTypes}
142
\li Relevant map features, for example highway, ferry
143
\endtable
144
145
146
In the following example a default \l [QML]{RouteQuery} is declared within \l [QML]{RouteModel}.
147
148
\snippet mapviewer/map/MapComponent.qml routemodel0
149
150
The user enters some information such as the starting point
151
of the route, some waypoints and the destination. All of these locations are
152
waypoints so the locations from start to finish will be entered as a sequence
153
of waypoints. Then other query properties can be set that may be specific to
154
this trip.
155
156
\snippet mapviewer/map/MapComponent.qml routerequest0
157
\snippet mapviewer/map/MapComponent.qml routerequest1
158
159
The \c routeInfoModel \l {Models and Views in Qt Quick#Models}{ListModel} is used to grab the
160
results of the query and construct a suitable list for display.
161
\snippet mapviewer/forms/RouteList.qml routeinfomodel0
162
\snippet mapviewer/forms/RouteList.qml routeinfomodel1
163
\snippet mapviewer/forms/RouteList.qml routeinfomodel3
164
165
The \l {Models and Views in Qt Quick#Models}{ListModel} \c routeInfoModel can be filled
166
with values using a code, that loops through the segments extracting the segment length,
167
instruction text and distance to the next instruction. The extracted data is formatted
168
for display as it is retrieved.
169
170
\snippet mapviewer/forms/RouteList.qml routeinfomodel2
171
172
For more information on the example see the \l {Map Viewer (QML)}{Map Viewer (QML)} example.
173
174
175
\section2 Zoom, Pinch and Flickable
176
177
The \l Map item also supports user interface interactions with the map using
178
tactile and mouse gestures. That is features such as swiping to pan,
179
pinching to zoom.
180
181
Enabling and configuring pinch and flickable is easy within the \l MapView type.
182
183
\snippet mapviewer/map/MapComponent.qml top
184
\snippet mapviewer/map/MapComponent.qml handler
185
\snippet mapviewer/map/MapComponent.qml end
186
187
Zoom can also be controlled by other objects like sliders, with binding
188
to the Map \l {QtLocation::Map::}{zoomLevel}.
189
190
\section1 QML Types
191
192
\section3 Maps
193
\annotatedlist qml-QtLocation5-maps
194
195
\section3 Geocoding
196
\annotatedlist qml-QtLocation5-geocoding
197
198
\section3 Routing
199
\annotatedlist qml-QtLocation5-routing
200
201
202
203
\section1 Example
204
205
The above snippets are taken from the \l {Map Viewer (QML)}{Map Viewer (QML)} example.
206
207
*/
qtlocation
src
location
doc
src
qml-maps.qdoc
Generated on
for Qt by
1.16.1