summaryrefslogtreecommitdiff
path: root/doc/src/qml-maps.qdoc
blob: 7edd4c85411f4693e678d131c794fd4ab0fd539b (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms
** and conditions contained in a signed written agreement between you
** and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \group qml-QtLocation5-maps
    \title QML Maps Plugin
    QML Support for the Qt Location API.
*/


/*!
\page qml-location5-maps.html
\title QML Maps
\previouspage {qtlocation-module.html}{QtLocation Module}

\brief Maps is the section QtQuick Location that deals with maps,
their contents and navigation through the maps. ???

\section1 Overview

The \l Map element allows the display of a map and placing objects within the map.
Various points of interest can be defined and added to the map for display.
Also the \l Map has features to control how the map is displayed. With the
Map item you can center the map, zoom, pinch and make the item flickable.

The places to be added to the map are \l {MapItem}s. The item's position is defined
by a \l {Coordinate::}{coordinate} which includes latitude, longitude and elevation. The item
is then displayed automatically after it is added to the Map. Interaction with
the added items, and the \l Map itself, is handled by \l MapMouseArea when items are
added as children of the \l {MapItem}s or \l Map.

\section2 Position

The basic element of position information is the \l Coordinate. A coordinate
encapsulates data for the latitude, longitude and altitude of the location.
Altitude is in meters. It also has a method to determine distance to another
Coordinate. The \l Coordinate element may also be held within a \l {QtLocation5::Location}{Location}
element, this will also have information on a bounding box size to determine
sufficient proximity to the location and a location address.

\section2 Geocoding

\l {http://en.wikipedia.org/wiki/Geocoding}{Geocoding} is the derivation of
geographical coordinates (latitude and longitude) from other geographical references
to the locations. For example, this can be a street address. Reverse geocoding is also possible with
a street address being used to determine a geographical coordinate. Geocoding
is performed by using the \l GeoCodeModel element.

The following code examples are a small part of the \c map component in the
\l {Declarative Map Viewer Example}{MapViewer QML example}. The snippets
demonstrate the declaration of the \l GeocodeModel component.

In the snippet we see that the \c geocodeModel property contains the plugin
and two signal handlers. One for changes in status (\c onStatusChanged ) and
the other to update the centering of the Map element (\c onLocationsChanged ).

\qml
    property GeocodeModel geocodeModel: GeocodeModel {
        plugin : map.plugin;
        onStatusChanged:{
            if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error)) map.geocodeFinished()
        }
        onLocationsChanged:
        {
            if (count == 1) {
                map.center.latitude = get(0).coordinate.latitude
                map.center.longitude = get(0).coordinate.longitude
            }

        }
    }
\endqml


\qml
    MapItemView {
        model: geocodeModel
        delegate: pointDelegate
    }
\endqml


These geocoding features are called from a higher level piece of code. In this
snippet we see an \c onGoButtonClicked signal handler that extracts the address
from the user interface and then creates a query for the \l GeocodeModel to
process and determine the geographical coordinates.


\qml
        Address {
            id: geocodeAddress
        }

        onGoButtonClicked: {
            // manage the UI state transitions
            page.state = ""
            messageDialog.state = ""

            // fill out the Address element
            geocodeAddress.street = dialogModel.get(0).inputText
            geocodeAddress.district = dialogModel.get(1).inputText
            geocodeAddress.city = dialogModel.get(2).inputText
            geocodeAddress.county = dialogModel.get(3).inputText
            geocodeAddress.state = dialogModel.get(4).inputText
            geocodeAddress.countryCode = dialogModel.get(5).inputText
            geocodeAddress.country = dialogModel.get(6).inputText
            geocodeAddress.postalCode = dialogModel.get(7).inputText

            // send the geocode request
            map.geocodeModel.clear()
            map.geocodeModel.query = geocodeAddress
            map.geocodeModel.update()
        }
\endqml


\section2 Navigation

A very important function of the \l Map element is navigation
from one place to a destination with possible waypoints along the route. The
route will be divided up into a series of segments. At the end of each segment
is a vertex called a \e maneuver. The \e segments contain information about
the time and distance to the end of the segment. The \e maneuvers contain information
about what to do next, how to get onto the next segment, if there is one. So
a \e maneuver contains navigational information, e.g. "turn right now".

To find a suitable route we will need to use a \l RouteQuery to define the
selection criteria and adding any required waypoints.
The \l RouteModel should return a list of \l {RouteSegment}s that defines the
route to the destination complete with navigation advice at the joins between
segments, called \l {RouteManeuver}s

There are many options that you can add to the query to narrow the criteria.
The \l RouteQuery properties can include

\table 60%
    \row
        \li \l {RouteQuery::}{numberAlternativeRoutes}
        \li The number of alternative routes
    \row
        \li \l {RouteQuery::}{travelModes}
        \li Travel modes
    \row
        \li \l {RouteQuery::}{routeOptimizations}
        \li Required route optimizations
    \row
        \li \l {RouteQuery::}{segmentDetails}
        \li Level of detail in segments
    \row
        \li \l {RouteQuery::}{maneuverDetails}
        \li Level of detail in maneuvers between segments
    \row
        \li \l {RouteQuery::}{waypoints}
        \li A list of waypoints
    \row
        \li \l {RouteQuery::}{excludedAreas}
        \li A list of excluded areas that the route must not cross
    \row
        \li \l {RouteQuery::}{featureTypes}
        \li Relevant map features, e.g. highway, ferry
\endtable


In the following example a default RouteQuery is declared, later to be defined
by some user input, and used in \c routeModel as the query. The \c routeInfoModel
is a \l ListModel that can be updated using an \c update() function that we will
look at later.

\qml
    property RouteQuery routeQuery: RouteQuery {}
    property RouteModel routeModel: RouteModel {
        plugin : map.plugin
        query: routeQuery
        onStatusChanged:{
            if (status == RouteModel.Ready){
                if (count == 1) { routeInfoModel.update()}
            }
            else if (status == RouteModel.Error){
                clearAll()
                map.routeError()
            }
        }
        function clearAll(){
            clear()
            routeInfoModel.update()
        }
    }
\endqml

The user enters, via a dialog, some information such as the starting point
of the route, some waypoints and the destination. All of these locations are
waypoints so the locations from start to finish will be entered as a sequence
of waypoints. Then other query properties can be set that may be specific to
this trip.

\qml
    function calculateRoute(){
        map.routeQuery.clearWaypoints();
        map.center = startCoordinate
        map.routeQuery.addWaypoint(startCoordinate)
        map.routeQuery.addWaypoint(endCoordinate)
        map.routeQuery.travelModes = routeDialog.travelMode
        map.routeQuery.routeOptimizations = routeDialog.routeOptimization

        for (var i=0; i<9; i++) {
            map.routeQuery.setFeatureWeight(i, 0)
        }

        for (var i=0; i<routeDialog.features.length; i++) {
            map.routeQuery.setFeatureWeight(routeDialog.features[i], RouteQuery.AvoidFeatureWeight)
        }

        map.routeModel.update();
    }
\endqml



The \c routeInfoModel \l ListModel is used to grab the results of the query and construct
a suitable list for display. The ListModel \c routeInfoModel contains an
\c update() function that loops through the segments extracting the segment
length, instruction text and distance to the next instruction. The extracted
data is formatted for display as it is retrieved.

\qml
    ListModel{
        id: routeInfoModel
        property string travelTime
        property string distance

        function update() {
            clear()
            if (routeModel.count > 0){
                for (var i=0; i< routeModel.get(0).segments.length; i++){
                    append({"instruction": routeModel.get(0).segments[i].maneuver.instructionText, "distance": formatDistance(routeModel.get(0).segments[i].maneuver.distanceToNextInstruction)})
                }
            }
            travelTime = routeModel.count == 0 ? "" : formatTime(routeModel.get(0).travelTime)
            distance = routeModel.count == 0 ? "" : formatDistance(routeModel.get(0).distance)
        }
    }

    MapItemView {
        model: routeModel
        delegate: routeDelegate
    }
\endqml

For more information on the example see the \l {Declarative Map Viewer Example}.


\section2  Zoom, Pinch and Flickable

The \l Map item also supports user interface interactions with the map using
tactile and mouse gestures. That is features such as swiping to pan,
pinching to zoom.

Enabling and configuring pinch and flickable is easy within the \l Map element.

\qml
    zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2


    // Enable pinch gestures to zoom in and out
    pinch.activeGestures: MapPinch.ZoomGesture
    pinch.enabled: true

    // And flicking gestures for quick panning
    flick.enabled: true
    flick.deceleration: 3000
\endqml

Zoom can also be controlled by other elements like sliders, as shown in the
example, by implementing the \c onValueChanged handler to update the Map
\l {QtLocation5::Map::}{zoomLevel}.





\section1 Elements

\section3 Positioning
\annotatedlist qml-QtLocation5-positioning

\section3 Maps
\annotatedlist qml-QtLocation5-maps

\section3 Geocoding
\annotatedlist qml-QtLocation5-geocoding

\section3 Routing
\annotatedlist qml-QtLocation5-routing



\section1 Example

The above snippets are taken from the \l {Declarative Map Viewer Example}.

*/