Display your current position on the map, as well as switch between different types of auto pan modes.
Use case
When using a map within a GIS, it may be helpful for a user to know their own location within a map, whether that's to aid the user's navigation or to provide an easy means of identifying/collecting geospatial information at their location.
How to use the sample
Tap the button in the lower right (which starts in Stop mode). A menu will appear with the following options:
Stop - Stops the location display.
On - Starts the location display with no AutoPanMode mode set.
Re-Center - Starts the location display with auto pan mode set to LocationDisplayAutoPanMode.Recenter.
Navigation - Starts the location display with auto pan mode set to LocationDisplayAutoPanMode.Navigation.
Compass - Starts the location display with auto pan mode set to LocationDisplayAutoPanMode.CompassNavigation.
How it works
Create a MapView.
Get the LocationDisplay object by calling locationDisplay on the map view.
Use start() and stop() on the location display object as necessary.
Relevant API
LocationDisplay
LocationDisplay.autoPanMode
Map
MapView
Additional information
Location permissions are required for this sample.
Tags
compass, GPS, location, map, mobile, navigation
Sample Code
DisplayDeviceLocation.qml
Use dark colors for code blocksCopy
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
// [WriteFile Name=DisplayDeviceLocation, Category=Maps]// [Legal]// Copyright 2016 Esri.// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]import QtQuick
import QtPositioning
import QtSensors
import Esri.ArcGISRuntime
Rectangle {
width: 800height: 600 readonly property string compassMode: "Compass" readonly property string navigationMode: "Navigation" readonly property string recenterMode: "Re-Center" readonly property string onMode: "On" readonly property string stopMode: "Stop" readonly property string closeMode: "Close"property string currentModeText: stopMode
property string currentModeImage: "qrc:/Samples/Maps/DisplayDeviceLocation/Stop.png"// Create MapView that contains a Map with the Imagery with Labels BasemapMapView {
id: mapViewanchors.fill: parentComponent.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation forceActiveFocus();
}
Map {
Basemap {
initStyle: Enums.BasemapStyleArcGISImageryStandard
}
// start the location displayonLoadStatusChanged: {
if (loadStatus === Enums.LoadStatusLoaded) {
// populate list model with modes autoPanListModel.append({name: compassMode, image: "qrc:/Samples/Maps/DisplayDeviceLocation/Compass.png"});
autoPanListModel.append({name: navigationMode, image: "qrc:/Samples/Maps/DisplayDeviceLocation/Navigation.png"});
autoPanListModel.append({name: recenterMode, image: "qrc:/Samples/Maps/DisplayDeviceLocation/Re-Center.png"});
autoPanListModel.append({name: onMode, image: "qrc:/Samples/Maps/DisplayDeviceLocation/On.png"});
autoPanListModel.append({name: stopMode, image: "qrc:/Samples/Maps/DisplayDeviceLocation/Stop.png"});
autoPanListModel.append({name: closeMode, image: "qrc:/Samples/Maps/DisplayDeviceLocation/Close.png"});
}
}
}
Component.onDestruction: {
mapView.locationDisplay.stop();
}
}
Rectangle {
id: rectanchors.fill: parentvisible: autoPanListView.visible
color: "black"opacity: 0.7 }
ListView {
id: autoPanListViewanchors {
right: parent.right
bottom: parent.bottom
margins: 10 }
visible: falsewidth: parent.width
height: 300spacing: 10model: ListModel {
id: autoPanListModel }
delegate: Row {
id: autopanRowanchors.right: parent.right
spacing: 10Text {
text: name
font.pixelSize: 25color: "white"MouseArea {
anchors.fill: parent// When an item in the list view is clickedonClicked: {
autopanRow.updateAutoPanMode();
}
}
}
Image {
source: image
width: 40height: width
MouseArea {
anchors.fill: parent// When an item in the list view is clickedonClicked: {
autopanRow.updateAutoPanMode();
}
}
}
// set the appropriate auto pan modefunctionupdateAutoPanMode() {
switch (name) {
casecompassMode:
mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeCompassNavigation;
mapView.locationDisplay.start();
break;
casenavigationMode:
mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeNavigation;
mapView.locationDisplay.start();
break;
caserecenterMode:
mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeRecenter;
mapView.locationDisplay.start();
break;
caseonMode:
mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeOff;
mapView.locationDisplay.start();
break;
casestopMode:
mapView.locationDisplay.stop();
break;
}
if (name !== closeMode) {
currentModeText = name;
currentModeImage = image;
}
// hide the list view currentAction.visible = true;
autoPanListView.visible = false;
}
}
}
Row {
id: currentActionanchors {
right: parent.right
bottom: parent.bottom
margins: 25 }
spacing: 10Text {
text: currentModeText
font.pixelSize: 25color: "white"MouseArea {
anchors.fill: parentonClicked: {
currentAction.visible = false;
autoPanListView.visible = true;
}
}
}
Image {
source: currentModeImage
width: 40height: width
MouseArea {
anchors.fill: parentonClicked: {
currentAction.visible = false;
autoPanListView.visible = true;
}
}
}
}
}