This file is indexed.

/usr/share/qt5/doc/qtlocation/qtlocation-mapviewer-example.html is in qtlocation5-doc-html 5.2.1-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- declarative-mapviewer.qdoc -->
  <title>Map Viewer (QML) | QtLocation 5.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li>Qt 5.2</li>
<li><a href="qtlocation-index.html">Qt Location</a></li>
<li>Map Viewer (QML)</li>
<li id="buildversion">
Qt 5.2.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level2"><a href="#displaying-a-map">Displaying a Map</a></li>
<li class="level2"><a href="#finding-an-address-geocoding">Finding an Address (Geocoding)</a></li>
<li class="level2"><a href="#directions-and-travel-routes">Directions and Travel Routes</a></li>
</ul>
</div>
<h1 class="title">Map Viewer (QML)</h1>
<span class="subtitle"></span>
<!-- $$$mapviewer-description -->
<div class="descr"> <a name="details"></a>
<p>The Map Viewer example shows how to display and interact with a map, search for an address, and find driving directions.<p>This is a large example covering many basic uses of maps, positioning, and navigation services in Qt Location. This page is divided into sections covering each of these areas of functionality with snippets from the code.</p>
<p>The Map Viewer example can work with any of the available geo services plugins. However, some plugins may require additional <a href="qml-qtlocation-pluginparameter.html">plugin parameters</a> in order to function correctly. <a href="qml-qtlocation-pluginparameter.html">Plugin parameters</a> can be passed on the command line using the <tt>--plugin</tt> argument, which takes the form:</p>
<pre class="cpp"><span class="operator">-</span><span class="operator">-</span>plugin<span class="operator">.</span><span class="operator">&lt;</span>parameter name<span class="operator">&gt;</span> <span class="operator">&lt;</span>parameter value<span class="operator">&gt;</span></pre>
<p>Refer to the documentation for each of the geo services plugins for details on what plugin parameters they support. The Nokia services plugin supplied with Qt requires an <i>app_id</i> and <i>token</i> pair. See &quot;<a href="location-plugin-nokia.html">Qt Location Nokia Plugin</a>&quot; for details.</p>
<p>QML types shown in this example:</p>
<ul>
<li>Displaying a map<ul>
<li><a href="qml-qtlocation-map.html">Map</a></li>
<li><a href="qml-qtlocation-mapgesturearea.html">MapGestureArea</a></li>
<li>coordinate</li>
</ul>
</li>
<li>Finding an address<ul>
<li><a href="qml-qtlocation-geocodemodel.html">GeocodeModel</a></li>
<li><a href="qml-qtlocation-mapitemview.html">MapItemView</a></li>
<li><a href="qml-qtlocation-mapcircle.html">MapCircle</a></li>
</ul>
</li>
<li>Directions and travel routes<ul>
<li><a href="qml-qtlocation-routemodel.html">RouteModel</a></li>
<li><a href="qml-qtlocation-maproute.html">MapRoute</a></li>
</ul>
</li>
</ul>
<p class="centerAlign"><img src="images/example-mapviewer.png" alt="" /></p><a name="displaying-a-map"></a>
<h3>Displaying a Map</h3>
<p>Drawing a map on-screen is accomplished using the Map type, as shown below.</p>
<pre class="qml"><span class="type"><a href="qml-qtlocation-map.html">Map</a></span> {
    <span class="name">id</span>: <span class="name">map</span>
    <span class="name">zoomLevel</span>: (<span class="name">maximumZoomLevel</span> <span class="operator">-</span> <span class="name">minimumZoomLevel</span>)<span class="operator">/</span><span class="number">2</span>

    <span class="type">center</span> {
        <span class="name">latitude</span>: -<span class="number">27.5796</span>
        <span class="name">longitude</span>: <span class="number">153.1003</span>
    }

    <span class="comment">// Enable pinch gestures to zoom in and out</span>
    <span class="name">gesture</span>.flickDeceleration: <span class="number">3000</span>
    <span class="name">gesture</span>.enabled: <span class="number">true</span>

<span class="type">center</span> {
    <span class="name">latitude</span>: -<span class="number">27.5796</span>
    <span class="name">longitude</span>: <span class="number">153.1003</span>
}
}</pre>
<p>In this example, we give the map an initial center coordinate with a set latitude and longitude. We also set the initial zoom level to 50% (halfway between the maximum and minimum).</p>
<p>The calls to &quot;pinch&quot; and &quot;flick&quot; are used to enable gestures on the map. The flick gesture is also sometimes known as &quot;kinetic panning&quot;, and provides a more intuitive feel for panning the map both on touch screens and with a mouse.</p>
<p>As we do not specify a plugin for supplying map data, the platform default will be used. This is typically the &quot;nokia&quot; plugin, which provides data from Nokia services. Additional licensing conditions do apply to the use of this data, please see the documentation for further details.</p>
<a name="finding-an-address-geocoding"></a>
<h3>Finding an Address (Geocoding)</h3>
<p>To locate a certain address or place on the map uses a process called geocoding. In order to perform a geocode operation, we first need to adjust our Map object to be able to receive the result.</p>
<p>Receiving results of geocoding is done through a <a href="qml-qtlocation-geocodemodel.html">GeocodeModel</a>, which is typically instantiated as a property of the Map component:</p>
<pre class="qml">    property <span class="type"><a href="qml-qtlocation-geocodemodel.html">GeocodeModel</a></span> <span class="name">geocodeModel</span>: <span class="name">GeocodeModel</span> {
    }</pre>
<p>Then, to display the contents of the <a href="qml-qtlocation-geocodemodel.html">GeocodeModel</a> we use a <a href="qml-qtlocation-mapitemview.html">MapItemView</a>:</p>
<pre class="qml">    <span class="type"><a href="qml-qtlocation-mapitemview.html">MapItemView</a></span> {
        <span class="name">model</span>: <span class="name">geocodeModel</span>
        <span class="name">delegate</span>: <span class="name">pointDelegate</span>
    }</pre>
<p><a href="qml-qtlocation-mapitemview.html">MapItemView</a> uses an object called a &quot;delegate&quot; to act as a template for the items it creates. This can contain any map object desired, but in this case we show a <a href="qml-qtlocation-mapcircle.html">MapCircle</a>:</p>
<pre class="qml">    <span class="type">Component</span> {
        <span class="name">id</span>: <span class="name">pointDelegate</span>

        <span class="type"><a href="qml-qtlocation-mapcircle.html">MapCircle</a></span> {
            <span class="name">radius</span>: <span class="number">1000</span>
            <span class="name">color</span>: <span class="name">circleMouseArea</span>.<span class="name">containsMouse</span> ? <span class="string">&quot;lime&quot;</span> : <span class="string">&quot;red&quot;</span>
            <span class="name">opacity</span>: <span class="number">0.6</span>
            <span class="name">center</span>: <span class="name">locationData</span>.<span class="name">coordinate</span>
        }
    }</pre>
<p>With these three objects, we have enough to receive Geocode responses and display them on our Map. The final piece is to send the actual Geocode request.</p>
<p>In this example, we have a utility component called Dialog which we use to display the user interface requesting geocoding parameters. You can create a similar component yourself using Dialog.qml in this example as a reference, or drive the process using any other UI you wish.</p>
<p>To send a geocode request, first we create an Address object, and fill it in with the desired parameters. Then we set &quot;map.<a href="qml-qtlocation-geocodemodel.html">geocodeModel</a>.query&quot; to the filled in Address, and call update() on the <a href="qml-qtlocation-geocodemodel.html">GeocodeModel</a>.</p>
<pre class="qml">    <span class="type">InputDialog</span> {
        <span class="name">id</span>: <span class="name">geocodeDialog</span>
        <span class="type">Address</span> {
            <span class="name">id</span>: <span class="name">geocodeAddress</span>
        }

        <span class="name">onGoButtonClicked</span>: {
            <span class="comment">// manage the UI state transitions</span>
            <span class="name">page</span>.<span class="name">state</span> <span class="operator">=</span> <span class="string">&quot;&quot;</span>
            <span class="name">messageDialog</span>.<span class="name">state</span> <span class="operator">=</span> <span class="string">&quot;&quot;</span>

            <span class="comment">// fill out the Address element</span>
            <span class="name">geocodeAddress</span>.<span class="name">street</span> <span class="operator">=</span> <span class="name">dialogModel</span>.<span class="name">get</span>(<span class="number">0</span>).<span class="name">inputText</span>
            <span class="name">geocodeAddress</span>.<span class="name">city</span> <span class="operator">=</span> <span class="name">dialogModel</span>.<span class="name">get</span>(<span class="number">1</span>).<span class="name">inputText</span>
            <span class="name">geocodeAddress</span>.<span class="name">state</span> <span class="operator">=</span> <span class="name">dialogModel</span>.<span class="name">get</span>(<span class="number">2</span>).<span class="name">inputText</span>
            <span class="name">geocodeAddress</span>.<span class="name">country</span> <span class="operator">=</span> <span class="name">dialogModel</span>.<span class="name">get</span>(<span class="number">3</span>).<span class="name">inputText</span>
            <span class="name">geocodeAddress</span>.<span class="name">postalCode</span> <span class="operator">=</span> <span class="name">dialogModel</span>.<span class="name">get</span>(<span class="number">4</span>).<span class="name">inputText</span>

            <span class="comment">// send the geocode request</span>
            <span class="name">map</span>.<span class="name">geocodeModel</span>.<span class="name">query</span> <span class="operator">=</span> <span class="name">geocodeAddress</span>
            <span class="name">map</span>.<span class="name">geocodeModel</span>.<span class="name">update</span>()
        }
    }</pre>
<a name="directions-and-travel-routes"></a>
<h3>Directions and Travel Routes</h3>
<p>Similar to the <a href="qml-qtlocation-geocodemodel.html">GeocodeModel</a>, Qt Location also features the <a href="qml-qtlocation-routemodel.html">RouteModel</a> type, which allows information about routes (for example driving directions) between two or more points, to be received and used with a Map.</p>
<p>Here again, we instantiate the <a href="qml-qtlocation-routemodel.html">RouteModel</a> as a property of our Map:</p>
<pre class="qml">    property <span class="type"><a href="qml-qtlocation-routequery.html">RouteQuery</a></span> <span class="name">routeQuery</span>: <span class="name">RouteQuery</span> {}

    property <span class="type"><a href="qml-qtlocation-routemodel.html">RouteModel</a></span> <span class="name">routeModel</span>: <span class="name">RouteModel</span> {
        <span class="name">plugin</span> : <span class="name">map</span>.<span class="name">plugin</span>
        <span class="name">query</span>: <span class="name">routeQuery</span>
    }</pre>
<p>To display the contents of a model to the user, we need a view. Once again we will use a <a href="qml-qtlocation-mapitemview.html">MapItemView</a>, to display the Routes as objects on the Map:</p>
<pre class="qml">    <span class="type"><a href="qml-qtlocation-mapitemview.html">MapItemView</a></span> {
        <span class="name">model</span>: <span class="name">routeModel</span>
        <span class="name">delegate</span>: <span class="name">routeDelegate</span>
        <span class="name">autoFitViewport</span>: <span class="number">true</span>
    }</pre>
<p>To act as a template for the objects we wish the view to create, we create a delegate component:</p>
<pre class="qml">    <span class="type">Component</span> {
        <span class="name">id</span>: <span class="name">routeDelegate</span>

        <span class="type"><a href="qml-qtlocation-maproute.html">MapRoute</a></span> {
            <span class="name">route</span>: <span class="name">routeData</span>

            <span class="name">line</span>.color: <span class="name">routeMouseArea</span>.<span class="name">containsMouse</span> ? <span class="string">&quot;lime&quot;</span> : <span class="string">&quot;red&quot;</span>
            <span class="name">line</span>.width: <span class="number">5</span>
            <span class="name">smooth</span>: <span class="number">true</span>
            <span class="name">opacity</span>: <span class="number">0.8</span>
    }</pre>
<p>With the model, view and delegate now complete, the only missing component is some kind of control over the model to begin the Route request process. In the simplest case, we can fill out a Route request using two already available coordinates, which we store inside the RouteDialog component:</p>
<pre class="qml">    <span class="type">RouteDialog</span> {
        <span class="name">id</span>: <span class="name">routeDialog</span>

        property <span class="type">variant</span> <span class="name">startCoordinate</span>
        property <span class="type">variant</span> <span class="name">endCoordinate</span>

    }</pre>
<p>In the next snippet, we show how to set up the request object and instruct the model to update. We also instruct the map to center on the start coordinate for our routing request.</p>
<pre class="qml">        <span class="keyword">function</span> <span class="name">calculateRoute</span>() {
            <span class="comment">// clear away any old data in the query</span>
            <span class="name">map</span>.<span class="name">routeQuery</span>.<span class="name">clearWaypoints</span>();

            <span class="comment">// add the start and end coords as waypoints on the route</span>
            <span class="name">map</span>.<span class="name">routeQuery</span>.<span class="name">addWaypoint</span>(<span class="name">startCoordinate</span>)
            <span class="name">map</span>.<span class="name">routeQuery</span>.<span class="name">addWaypoint</span>(<span class="name">endCoordinate</span>)
            <span class="name">map</span>.<span class="name">routeQuery</span>.<span class="name">travelModes</span> <span class="operator">=</span> <span class="name">routeDialog</span>.<span class="name">travelMode</span>
            <span class="name">map</span>.<span class="name">routeQuery</span>.<span class="name">routeOptimizations</span> <span class="operator">=</span> <span class="name">routeDialog</span>.<span class="name">routeOptimization</span>
            <span class="name">map</span>.<span class="name">routeModel</span>.<span class="name">update</span>();

            <span class="comment">// center the map on the start coord</span>
            <span class="name">map</span>.<span class="name">center</span> <span class="operator">=</span> <span class="name">startCoordinate</span>;</pre>
<p>This is all that is required to display a Route on the Map. However, it is also useful to be able to retrieve the written directions and explanation of the travel route. In the example, these are displayed in the pull-out on the left-hand side of the map. To create this pull-out's contents, we use a standard ListModel and ListView pair. The data in the ListModel is built from the <a href="qml-qtlocation-routemodel.html">routeModel</a>'s output:</p>
<pre class="qml">    <span class="type">ListModel</span> {
        <span class="name">id</span>: <span class="name">routeInfoModel</span>

        property <span class="type">string</span> <span class="name">travelTime</span>
        property <span class="type">string</span> <span class="name">distance</span>

        <span class="keyword">function</span> <span class="name">update</span>() {
            <span class="name">clear</span>()
            <span class="keyword">if</span> (<span class="name">routeModel</span>.<span class="name">count</span> <span class="operator">&gt;</span> <span class="number">0</span>) {
                <span class="keyword">for</span> (<span class="keyword">var</span> <span class="name">i</span> = <span class="number">0</span>; <span class="name">i</span> <span class="operator">&lt;</span> <span class="name">routeModel</span>.<span class="name">get</span>(<span class="number">0</span>).<span class="name">segments</span>.<span class="name">length</span>; i++) {
                    <span class="name">append</span>({
                        &quot;instruction&quot;: <span class="name">routeModel</span>.<span class="name">get</span>(<span class="number">0</span>).<span class="name">segments</span>[<span class="name">i</span>].<span class="name">maneuver</span>.<span class="name">instructionText</span>,
                        &quot;distance&quot;: <span class="name">formatDistance</span>(<span class="name">routeModel</span>.<span class="name">get</span>(<span class="number">0</span>).<span class="name">segments</span>[<span class="name">i</span>].<span class="name">maneuver</span>.<span class="name">distanceToNextInstruction</span>)
                    });
                }
            }
            <span class="name">travelTime</span> <span class="operator">=</span> <span class="name">routeModel</span>.<span class="name">count</span> <span class="operator">==</span> <span class="number">0</span> ? <span class="string">&quot;&quot;</span> : <span class="name">formatTime</span>(<span class="name">routeModel</span>.<span class="name">get</span>(<span class="number">0</span>).<span class="name">travelTime</span>)
            <span class="name">distance</span> <span class="operator">=</span> <span class="name">routeModel</span>.<span class="name">count</span> <span class="operator">==</span> <span class="number">0</span> ? <span class="string">&quot;&quot;</span> : <span class="name">formatDistance</span>(<span class="name">routeModel</span>.<span class="name">get</span>(<span class="number">0</span>).<span class="name">distance</span>)
        }
    }</pre>
<p>Inside the <a href="qml-qtlocation-routemodel.html">RouteModel</a>, we add an <a href="qml-qtlocation-routemodel.html#status-prop">onStatusChanged</a> handler, which calls the <tt>update()</tt> function we defined on the model:</p>
<pre class="qml">        <span class="name">onStatusChanged</span>: {
            <span class="keyword">if</span> (<span class="name">status</span> <span class="operator">==</span> <span class="name">RouteModel</span>.<span class="name">Ready</span>) {
                <span class="keyword">switch</span> (<span class="name">count</span>) {
                <span class="keyword">case</span> <span class="number">0</span>:
                    <span class="name">clearAll</span>() <span class="comment">// technically not an error</span>
                    <span class="name">map</span>.<span class="name">routeError</span>()
                    <span class="keyword">break</span>
                <span class="keyword">case</span> <span class="number">1</span>:
                    <span class="name">routeInfoModel</span>.<span class="name">update</span>()
                    <span class="keyword">break</span>
                }
            } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="name">status</span> <span class="operator">==</span> <span class="name">RouteModel</span>.<span class="name">Error</span>) {
                <span class="name">clearAll</span>()
                <span class="name">map</span>.<span class="name">routeError</span>()
            }
        }</pre>
<p>Files:</p>
<ul>
<li><a href="qtlocation-mapviewer-mapviewer-qml.html">mapviewer/mapviewer.qml</a></li>
<li><a href="qtlocation-mapviewer-qmlmapviewerwrapper-cpp.html">mapviewer/qmlmapviewerwrapper.cpp</a></li>
<li><a href="qtlocation-mapviewer-content-dialogs-message-qml.html">mapviewer/content/dialogs/Message.qml</a></li>
<li><a href="qtlocation-mapviewer-content-dialogs-routedialog-qml.html">mapviewer/content/dialogs/RouteDialog.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-3ditem-qml.html">mapviewer/content/map/3dItem.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-circleitem-qml.html">mapviewer/content/map/CircleItem.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-imageitem-qml.html">mapviewer/content/map/ImageItem.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-mapcomponent-qml.html">mapviewer/content/map/MapComponent.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-marker-qml.html">mapviewer/content/map/Marker.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-minimap-qml.html">mapviewer/content/map/MiniMap.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-polygonitem-qml.html">mapviewer/content/map/PolygonItem.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-polylineitem-qml.html">mapviewer/content/map/PolylineItem.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-rectangleitem-qml.html">mapviewer/content/map/RectangleItem.qml</a></li>
<li><a href="qtlocation-mapviewer-content-map-videoitem-qml.html">mapviewer/content/map/VideoItem.qml</a></li>
<li><a href="qtlocation-mapviewer-mapviewer-pro.html">mapviewer/mapviewer.pro</a></li>
<li><a href="qtlocation-mapviewer-mapviewerwrapper-qrc.html">mapviewer/mapviewerwrapper.qrc</a></li>
</ul>
</div>
<!-- @@@mapviewer -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
   subsidiaries. Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Digia, Qt and their respective logos are trademarks of Digia Plc     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>