Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
19The \l Map type allows the display of a map and placing objects within the map.
20Various points of interest can be defined and added to the map for display.
21Also the \l Map has features to control how the map is displayed. With the
22Map item you can center the map, zoom, pinch and make the item flickable.
23
24The 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
26position is defined by a \l {coordinate} which includes latitude,
27longitude and altitude. The item is then displayed automatically after it is added to the \l Map.
28
29\section2 Position on map
30
31All position APIs are part of the \l {QtPositioning} module.
32The basic piece of position information is the \l {coordinate}. A
33coordinate encapsulates data for the latitude, longitude and altitude of the location. Altitude is
34in meters. It also has a method to determine distance to another
35\l {coordinate}. The \l {coordinate} type may
36also be held within a \l [QtPositioning]{Location} element, this will also have information
37on a bounding box size to determine sufficient proximity to the location and a location address.
38
39
40Here is an example of a client that uses a \l{PositionSource}{position source}
41to 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
68geographical coordinates (latitude and longitude) from other geographical references
69to the locations. For example, this can be a street address. Reverse geocoding is also possible with
70a street address being used to determine a geographical coordinate. Geocoding
71is performed by using the \l [QML]{GeocodeModel} type.
72
73The 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
75demonstrate the declaration of the \l GeocodeModel component.
76
77In the snippet we see that the [QML]{GeocodeModel} contains the plugin
78and two signal handlers. One for changes in status \l [QML]{GeocodeModel::status}{\c onStatusChanged} and
79the 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
85The geocoding features are called from a higher level piece of code. In this
86snippet we see an \l [QML]{Address} object filled with the desired parameters.
87
88\snippet mapviewer/Main.qml geocode0
89
90The \l [QML]{Address} is later used in a query for the \l GeocodeModel to
91process and determine the geographical \l [QML]{coordinate}{coordinates}.
92
93\snippet mapviewer/map/MapComponent.qml geocode1
94
95
96\section2 Navigation
97
98A very important function of the \l Map type is navigation
99from one place to a destination with possible waypoints along the route. The
100route will be divided up into a series of segments. At the end of each segment
101is a vertex called a \e maneuver. The \e segments contain information about
102the time and distance to the end of the segment. The \e maneuvers contain information
103about what to do next, how to get onto the next segment, if there is one. So
104a \e maneuver contains navigational information, for example "turn right now".
105
106To find a suitable route we will need to use a \l RouteQuery to define the
107selection criteria and adding any required waypoints.
108The \l RouteModel should return a list of \l {routeSegment}s that defines the
109route to the destination complete with navigation advice at the joins between
110segments, called \l {routeManeuver}s
111
112There are many options that you can add to the query to narrow the criteria.
113The \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
143In the following example a default \l [QML]{RouteQuery} is declared within \l [QML]{RouteModel}.
144
145\snippet mapviewer/map/MapComponent.qml routemodel0
146
147The user enters some information such as the starting point
148of the route, some waypoints and the destination. All of these locations are
149waypoints so the locations from start to finish will be entered as a sequence
150of waypoints. Then other query properties can be set that may be specific to
151this trip.
152
153\snippet mapviewer/map/MapComponent.qml routerequest0
154\snippet mapviewer/map/MapComponent.qml routerequest1
155
156The \c routeInfoModel \l {Models and Views in Qt Quick#Models}{ListModel} is used to grab the
157results 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
162The \l {Models and Views in Qt Quick#Models}{ListModel} \c routeInfoModel can be filled
163with values using a code, that loops through the segments extracting the segment length,
164instruction text and distance to the next instruction. The extracted data is formatted
165for display as it is retrieved.
166
167\snippet mapviewer/forms/RouteList.qml routeinfomodel2
168
169For more information on the example see the \l {Map Viewer (QML)}{Map Viewer (QML)} example.
170
171
172\section2 Zoom, Pinch and Flickable
173
174The \l Map item also supports user interface interactions with the map using
175tactile and mouse gestures. That is features such as swiping to pan,
176pinching to zoom.
177
178Enabling 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
184Zoom can also be controlled by other objects like sliders, with binding
185to 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
202The above snippets are taken from the \l {Map Viewer (QML)}{Map Viewer (QML)} example.
203
204*/
205