Show device location using indoor positioning

View inC++QMLView on GitHubSample viewer app

Show your device's real-time location while inside a building by using signals from indoor positioning beacons.

screenshot

Use case

An indoor positioning system (IPS) allows you to locate yourself and others inside a building in real time. Similar to GPS, it puts a blue dot on indoor maps and can be used with other location services to help navigate to any point of interest or destination, as well as provide an easy way to identify and collect geospatial information at their location.

How to use the sample

When the device is within range of an IPS beacon, toggle "Show Location" to change the visibility of the location indicator in the map view. The system will ask for permission to use the device's location if the user has not yet used location services in this app. It will then start the location display with auto-pan mode set to navigation.

When there are no IPS beacons nearby, or other errors occur while initializing the indoors location data source, it will seamlessly fall back to the current device location as determined by GPS.

How it works

  1. Load an IPS-enabled map. This can be a web map hosted as a portal item in ArcGIS Online, an Enterprise Portal, or a mobile map package (.mmpk) created with ArcGIS Pro.
  2. Create an IndoorsLocationDataSource with the positioning feature table (stored with the map) and the pathways feature table after both tables are loaded.
  3. Handle location change events to respond to floor changes or read other metadata for locations.
  4. Set the IndoorsLocationDataSource to the map view's location display.
  5. Set the auto pan mode to Navigation to zoom to and follow the user's location.
  6. Enable the map view's location display using LocationDisplay.start(). Device location will appear on the display as a blue dot and update as the user moves throughout the space.

Relevant API

  • ArcGISFeatureTable
  • FeatureTable
  • IndoorsLocationDataSource
  • LocationDisplay
  • LocationDisplayAutoPanMode
  • Map
  • MapView

About the data

This sample uses an IPS-enabled web map that displays Building L on the Esri Redlands campus. Please note: you would only be able to use the indoor positioning functionalities when you are inside this building. Swap the web map to test with your own IPS setup.

Additional information

  • Location and Bluetooth permissions are required for this sample.
  • To learn more about IPS, read the Indoor positioning article on ArcGIS Developer website.
  • To learn more about how to deploy the indoor positioning system, read the Deploy ArcGIS IPS article.

Tags

beacon, BLE, blue dot, Bluetooth, building, facility, GPS, indoor, IPS, location, map, mobile, navigation, site, transmitter

Sample Code

ShowDeviceLocationUsingIndoorPositioning.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
195
196
197
// [WriteFile Name=ShowDeviceLocationUsingIndoorPositioning, Category=Maps]
// [Legal]
// Copyright 2022 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 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.13
import Esri.ArcGISRuntime 100.15

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    property FeatureTable positioningTable: null
    property ArcGISFeatureTable pathwaysTable: null
    property int currentFloor: -1
    property var locationProperties: ({})

    onPositioningTableChanged: setupIndoors()
    onPathwaysTableChanged: setupIndoors()
    onCurrentFloorChanged: changeFloorDisplay()

    MapView {
        id: mapView
        anchors.fill: parent

        Component.onCompleted: {
            // Set and keep the focus on MapView to enable keyboard navigation
            forceActiveFocus();
        }

        Map {
            id: map
            PortalItem {
                itemId: "8fa941613b4b4b2b8a34ad4cdc3e4bba"
            }

            onLoadStatusChanged: {
                if (loadStatus !== Enums.LoadStatusLoaded)
                    return;

                findPositioningTable("ips_positioning")
                findPathwaysTable("Pathways");
            }
        }
    }

    Rectangle {
        id: locationInformationRectangle
        width: parent.width
        height: textColumn.height + 20
        color: "lightgray"

        ColumnLayout {
            id: textColumn
            anchors {
                top: parent.top
                left: parent.left
                margins: 10
            }

            Text {
                id: initializingText
                text: "Initializing location data source\nand retrieving user location..."
                visible: true
            }

            Text {
                id: floorText
                visible: false
            }
            Text {
                id: positionSourceText
                visible: false
            }
            Text {
                id: transmitterCountText
                visible: false
            }
            Text {
                id: horizontalAccuracyText
                visible: false
            }
        }
    }

    // An IPS positioning feature table is stored with an IPS-enabled map. Each row in the table contains an indoor positioning file.
    // The IndoorsLocationDataSource will use the most recently created row unless given an alternative GlobalId in the constructor.
    function findPositioningTable(tableName) {
        map.tables.forEach((table) => {
           if (table.loadStatus === Enums.LoadStatusLoaded) {
               if (table.tableName === tableName) {
                   positioningTable = table;
                   return;
               }
           } else {
               table.loadStatusChanged.connect(() => {
                   if (table.loadStatus === Enums.LoadStatusLoaded && table.tableName === tableName) {
                       positioningTable = table;
                   }
               });
               table.load();
           }
       });
    }

    // The pathways table is an ArcGISFeatureTable with line features that represent paths through the indoor space.
    // Locations provided by the IndoorsLocationDataSource are snapped to the lines in this feature class.
    function findPathwaysTable(layerName) {
        for (let i = 0; i < map.operationalLayers.count; ++i) {
            const layer = map.operationalLayers.get(i);
            if (layer.name === layerName && layer.layerType === Enums.LayerTypeFeatureLayer) {
                const table = layer.featureTable;
                if (table.featureTableType === Enums.FeatureTableTypeServiceFeatureTable) {
                    pathwaysTable = table;
                    return;
                }
            }
        }
    }

    function setupIndoors() {
        if (!positioningTable || !pathwaysTable)
            return;

        const indoorsLDS = ArcGISRuntimeEnvironment.createObject("IndoorsLocationDataSource",
                                                                 {
                                                                     positioningTable: positioningTable,
                                                                     pathwaysTable: pathwaysTable
                                                                 });

        // Update information text box and floor view if necessary
        mapView.locationDisplay.locationChanged.connect(() => {
            if (mapView.locationDisplay.location !== undefined) {
                initializingText.visible = false;
            } else {
                initializingText.visible = true;
            }

            if (mapView.locationDisplay.location.additionalSourceProperties.floor !== undefined) {
                currentFloor = mapView.locationDisplay.location.additionalSourceProperties.floor;
                floorText.text = "Floor: " + currentFloor;
                floorText.visible = true;
            } else {
                floorText.visible = false;
            }

            if (mapView.locationDisplay.location.additionalSourceProperties.positionSource !== undefined) {
                positionSourceText.text = "Position Source: " + mapView.locationDisplay.location.additionalSourceProperties.positionSource;
                positionSourceText.visible = true;
            } else {
                positionSourceText.visible = false;
            }

            if (mapView.locationDisplay.location.additionalSourceProperties.satelliteCount !== undefined) {
                transmitterCountText.text = "Transmitter Count: " + mapView.locationDisplay.location.additionalSourceProperties.satelliteCount;
                transmitterCountText.visible = true;
            } else {
                transmitterCountText.visible = false;
            }

            if (mapView.locationDisplay.location.horizontalAccuracy !== undefined) {
                horizontalAccuracyText.text = "Horizontal accuracy: " + mapView.locationDisplay.location.horizontalAccuracy.toFixed(2) + " m";
                horizontalAccuracyText.visible = true;
            } else {
                horizontalAccuracyText.visible = false;
            }
        });

        mapView.locationDisplay.dataSource = indoorsLDS;
        mapView.locationDisplay.start();
    }

    // Toggle the visibility of floor features depending on the user's current floor
    function changeFloorDisplay() {
        const layers = map.operationalLayers;
        layers.forEach((layer) => {
            if (["Details", "Units", "Levels"].includes(layer.name)) {
                layer.definitionExpression = "VERTICAL_ORDER = " + currentFloor;
            }
        });
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.