1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \group qml-QtLocation5-maps
7 QML Support for the Qt Location API.
12\page qml-location5-maps.html
15\brief Maps deals with maps, their contents and navigation.
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.
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.
29\section2 Position on map
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.
40Here is an example of a client that uses a \l{PositionSource}{position source}
41to center a \l{Map}{map} on the current position:
58 // center the map on the current position
59 map.center = position.coordinate
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.
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.
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}.
81\snippet mapviewer/map/MapComponent.qml geocodemodel0
83\snippet mapviewer/map/MapComponent.qml geocodeview
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.
88\snippet mapviewer/Main.qml geocode0
90The \l [QML]{Address} is later used in a query for the \l GeocodeModel to
91process and determine the geographical \l [QML]{coordinate}{coordinates}.
93\snippet mapviewer/map/MapComponent.qml geocode1
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".
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
112There are many options that you can add to the query to narrow the criteria.
113The \l RouteQuery properties can include
117 \li \l {RouteQuery::}{numberAlternativeRoutes}
118 \li The number of alternative routes
120 \li \l {RouteQuery::}{travelModes}
123 \li \l {RouteQuery::}{routeOptimizations}
124 \li Required route optimizations
126 \li \l {RouteQuery::}{segmentDetail}
127 \li Level of detail in segments
129 \li \l {RouteQuery::}{maneuverDetail}
130 \li Level of detail in maneuvers between segments
132 \li \l {RouteQuery::}{waypoints}
133 \li A list of waypoints
135 \li \l {RouteQuery::}{excludedAreas}
136 \li A list of excluded areas that the route must not cross
138 \li \l {RouteQuery::}{featureTypes}
139 \li Relevant map features, for example highway, ferry
143In the following example a default \l [QML]{RouteQuery} is declared within \l [QML]{RouteModel}.
145\snippet mapviewer/map/MapComponent.qml routemodel0
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
153\snippet mapviewer/map/MapComponent.qml routerequest0
154\snippet mapviewer/map/MapComponent.qml routerequest1
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
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.
167\snippet mapviewer/forms/RouteList.qml routeinfomodel2
169For more information on the example see the \l {Map Viewer (QML)}{Map Viewer (QML)} example.
172\section2 Zoom, Pinch and Flickable
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,
178Enabling and configuring pinch and flickable is easy within the \l MapView type.
180\snippet mapviewer/map/MapComponent.qml top
181\snippet mapviewer/map/MapComponent.qml handler
182\snippet mapviewer/map/MapComponent.qml end
184Zoom can also be controlled by other objects like sliders, with binding
185to the Map \l {QtLocation::Map::}{zoomLevel}.
190\annotatedlist qml-QtLocation5-maps
193\annotatedlist qml-QtLocation5-geocoding
196\annotatedlist qml-QtLocation5-routing
202The above snippets are taken from the \l {Map Viewer (QML)}{Map Viewer (QML)} example.