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