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

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
- 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.
- Create an
IndoorsLocationDataSourcewith the positioning feature table (stored with the map) and the pathways feature table after both tables are loaded. - Handle location change events to respond to floor changes or read other metadata for locations.
- Set the
IndoorsLocationDataSourceto the map view’s location display. - Set the auto pan mode to
Navigationto zoom to and follow the user’s location. - 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
// [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]
// sample headers#include "IndoorsLocationDataSourceCreator.h"
// ArcGIS Maps SDK headers#include "ArcGISFeatureTable.h"#include "Error.h"#include "FeatureLayer.h"#include "FeatureTableListModel.h"#include "IndoorsLocationDataSource.h"#include "LayerListModel.h"#include "Map.h"#include "MapTypes.h"
using namespace Esri::ArcGISRuntime;
IndoorsLocationDataSourceCreator::IndoorsLocationDataSourceCreator(QObject* parent /* = nullptr */): QObject(parent){}
IndoorsLocationDataSourceCreator::~IndoorsLocationDataSourceCreator() = default;
void IndoorsLocationDataSourceCreator::createIndoorsLocationDataSource(Map* map, const QString& positioningTableName, const QString& pathwaysTableName, const QUuid& globalId){ if (map->loadStatus() != LoadStatus::Loaded) { connect(map, &Map::doneLoading, this, [map, positioningTableName, pathwaysTableName, globalId, this]() { createIndoorsLocationDataSource(map, positioningTableName, pathwaysTableName, globalId); }); return; }
m_map = map;
m_positioningTableName = positioningTableName; m_pathwaysTableName = pathwaysTableName; m_globalId = globalId;
findPositioningTable(); findPathwaysTable();}
// 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.void IndoorsLocationDataSourceCreator::findPositioningTable(){ FeatureTableListModel* tables = m_map->tables();
for (FeatureTable* table : *tables) { if (table->loadStatus() == LoadStatus::Loaded) { if (table->tableName() == m_positioningTableName) { m_positioningTable = table;
if (m_pathwaysTable && m_positioningTable) returnIndoorsLocationDataSource(); } } else { connect(table, &FeatureTable::doneLoading, this, [table, this]() { if (table->tableName() == m_positioningTableName) { m_positioningTable = table;
if (m_pathwaysTable && m_positioningTable) returnIndoorsLocationDataSource(); } });
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.void IndoorsLocationDataSourceCreator::findPathwaysTable(){ LayerListModel* layers = m_map->operationalLayers();
for (Layer* layer : *layers) { if (FeatureLayer* featureLayer = dynamic_cast<FeatureLayer*>(layer)) { if (featureLayer->name() == m_pathwaysTableName) { m_pathwaysTable = dynamic_cast<ArcGISFeatureTable*>(featureLayer->featureTable());
if (m_pathwaysTable && m_positioningTable) returnIndoorsLocationDataSource();
return; } } }}
void IndoorsLocationDataSourceCreator::returnIndoorsLocationDataSource(){ // The IndoorsLocationDataSource constructor takes an optional GlobalId to identify which row of the positioning table to use. // If not specified, the constructor will use the row from the most recent survey if (m_globalId.isNull()) emit createIndoorsLocationDataSourceCompleted(new IndoorsLocationDataSource(m_positioningTable, m_pathwaysTable, this)); else emit createIndoorsLocationDataSourceCompleted(new IndoorsLocationDataSource(m_positioningTable, m_pathwaysTable, m_globalId, this));}// [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]
// 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.
#ifndef INDOORSLOCATIONDATASOURCECREATOR_H#define INDOORSLOCATIONDATASOURCECREATOR_H
// Qt headers#include <QObject>#include <QUuid>
namespace Esri::ArcGISRuntime{class ArcGISFeatureTable;class FeatureTable;class IndoorsLocationDataSource;class Map;}
class IndoorsLocationDataSourceCreator : public QObject{ Q_OBJECT
public: IndoorsLocationDataSourceCreator(QObject* parent = nullptr); ~IndoorsLocationDataSourceCreator();
public slots: void createIndoorsLocationDataSource(Esri::ArcGISRuntime::Map* map, const QString& positioningTableName, const QString& pathwaysTableName, const QUuid& globalId = QUuid());
signals: void createIndoorsLocationDataSourceCompleted(Esri::ArcGISRuntime::IndoorsLocationDataSource* IndoorsLocationDataSource);
private: void returnIndoorsLocationDataSource(); void findPositioningTable(); void findPathwaysTable();
Esri::ArcGISRuntime::Map* m_map = nullptr; Esri::ArcGISRuntime::FeatureTable* m_positioningTable = nullptr; Esri::ArcGISRuntime::ArcGISFeatureTable* m_pathwaysTable = nullptr; QUuid m_globalId; QString m_positioningTableName; QString m_pathwaysTableName; QStringList m_globalIdSortNames;};
#endif // INDOORSLOCATIONDATASOURCECREATOR_H// [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]
#ifdef PCH_BUILD#include "pch.hpp"#endif // PCH_BUILD
// sample headers#include "IndoorsLocationDataSourceCreator.h"#include "ShowDeviceLocationUsingIndoorPositioning.h"
// ArcGIS Maps SDK headers#include "FeatureLayer.h"#include "IndoorsLocationDataSource.h"#include "LayerListModel.h"#include "LocationDisplay.h"#include "Map.h"#include "MapQuickView.h"#include "MapTypes.h"#include "MapViewTypes.h"#include "PortalItem.h"
// Qt headers#include <QMetaObject>#include <QPermissions>
// Platform specific headers#ifdef Q_OS_ANDROID#include "ArcGISRuntimeEnvironment.h"
#include <QCoreApplication>#include <QJniObject>#endif
using namespace Esri::ArcGISRuntime;
namespace {const QString itemId = "8fa941613b4b4b2b8a34ad4cdc3e4bba";
const QString positioningTableName = "ips_positioning";const QString pathwaysLayerName = "Pathways";const QStringList globalIdSortNames = {"DateCreated", "DATE_CREATED"};
const QStringList layerNames = {"Details", "Units", "Levels"};}
ShowDeviceLocationUsingIndoorPositioning::ShowDeviceLocationUsingIndoorPositioning(QObject* parent /* = nullptr */): QObject(parent){ m_map = new Map(new PortalItem(itemId, this), this);}
ShowDeviceLocationUsingIndoorPositioning::~ShowDeviceLocationUsingIndoorPositioning() = default;
void ShowDeviceLocationUsingIndoorPositioning::stopLocationDisplay(){ m_mapView->locationDisplay()->stop();}
void ShowDeviceLocationUsingIndoorPositioning::init(){ // Register the map view for QML qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView"); qmlRegisterType<ShowDeviceLocationUsingIndoorPositioning>("Esri.Samples", 1, 0, "ShowDeviceLocationUsingIndoorPositioningSample");}
MapQuickView* ShowDeviceLocationUsingIndoorPositioning::mapView() const{ return m_mapView;}
// Set the view (created in QML)void ShowDeviceLocationUsingIndoorPositioning::setMapView(MapQuickView* mapView){ if (!mapView || mapView == m_mapView) return;
m_mapView = mapView; m_mapView->setMap(m_map);
// workaround for https://bugreports.qt.io/browse/QTBUG-134211 QMetaObject::invokeMethod(this, [this](){ requestBluetoothThenLocationPermissions(); }, Qt::QueuedConnection);
emit mapViewChanged();}
void ShowDeviceLocationUsingIndoorPositioning::requestBluetoothThenLocationPermissions(){ qApp->requestPermission(QBluetoothPermission{}, [this](const QPermission& permission) { Q_UNUSED(permission); requestLocationPermissionThenSetupILDS(); });}
void ShowDeviceLocationUsingIndoorPositioning::requestLocationPermissionThenSetupILDS(){ QLocationPermission locationPermission{}; locationPermission.setAccuracy(QLocationPermission::Accuracy::Precise); locationPermission.setAvailability(QLocationPermission::Availability::WhenInUse); qApp->requestPermission(locationPermission, [this](const QPermission& permission) { Q_UNUSED(permission); checkPermissions(); setupIndoorsLocationDataSource(); });}
void ShowDeviceLocationUsingIndoorPositioning::checkPermissions(){ if (qApp->checkPermission(QBluetoothPermission{}) == Qt::PermissionStatus::Denied) { emit bluetoothPermissionDenied(); }
QLocationPermission locationPermission{}; locationPermission.setAccuracy(QLocationPermission::Accuracy::Precise); locationPermission.setAvailability(QLocationPermission::Availability::WhenInUse); if (qApp->checkPermission(locationPermission) == Qt::PermissionStatus::Denied) { emit locationPermissionDenied(); }}
// This function uses a helper class `IndoorsLocationDataSourceCreator` to construct the IndoorsLocationDataSourcevoid ShowDeviceLocationUsingIndoorPositioning::setupIndoorsLocationDataSource(){ #ifdef Q_OS_ANDROID ArcGISRuntimeEnvironment::setAndroidApplicationContext(QJniObject{QNativeInterface::QAndroidApplication::context()}); #endif
IndoorsLocationDataSourceCreator* indoorsLocationDataSourceCreator = new IndoorsLocationDataSourceCreator(this);
connect(indoorsLocationDataSourceCreator, &IndoorsLocationDataSourceCreator::createIndoorsLocationDataSourceCompleted, this, [this](IndoorsLocationDataSource* indoorsLDS) { connect(m_mapView->locationDisplay(), &LocationDisplay::locationChanged, this, &ShowDeviceLocationUsingIndoorPositioning::locationChangedHandler);
m_mapView->locationDisplay()->setDataSource(indoorsLDS); m_mapView->locationDisplay()->setAutoPanMode(LocationDisplayAutoPanMode::Navigation); m_mapView->locationDisplay()->start(); });
indoorsLocationDataSourceCreator->createIndoorsLocationDataSource(m_map, positioningTableName, pathwaysLayerName);}
// Change currently displayed location information and change floor display if necessaryvoid ShowDeviceLocationUsingIndoorPositioning::locationChangedHandler(const Location& loc){ if (m_locationProperties["floor"] != m_currentFloor) { m_currentFloor = m_locationProperties["floor"].toInt(); changeFloorDisplay(); } m_locationProperties = loc.additionalSourceProperties(); m_locationProperties["horizontalAccuracy"] = QVariant::fromValue(loc.horizontalAccuracy());
emit locationPropertiesChanged();}
void ShowDeviceLocationUsingIndoorPositioning::changeFloorDisplay(){ for (Layer* layer : *(m_map->operationalLayers())) { if (layerNames.contains(layer->name())) { if (layer->layerType() == LayerType::FeatureLayer) { FeatureLayer* featureLayer = static_cast<FeatureLayer*>(layer); featureLayer->setDefinitionExpression(QString{"VERTICAL_ORDER = %1"}.arg(m_currentFloor)); } } }}
QVariantMap ShowDeviceLocationUsingIndoorPositioning::locationProperties() const { return m_locationProperties; }// [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]
#ifndef SHOWDEVICELOCATIONUSINGINDOORPOSITIONING_H#define SHOWDEVICELOCATIONUSINGINDOORPOSITIONING_H
// ArcGIS Maps SDK headers#include "Location.h"
// Qt headers#include <QMap>#include <QObject>
namespace Esri::ArcGISRuntime{class ArcGISFeatureTable;class FeatureTable;class Map;class MapQuickView;}
Q_MOC_INCLUDE("MapQuickView.h")
class ShowDeviceLocationUsingIndoorPositioning : public QObject{ Q_OBJECT
Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged) Q_PROPERTY(QVariantMap locationProperties READ locationProperties NOTIFY locationPropertiesChanged)
public: explicit ShowDeviceLocationUsingIndoorPositioning(QObject* parent = nullptr); ~ShowDeviceLocationUsingIndoorPositioning();
static void init();
Q_INVOKABLE void stopLocationDisplay();
signals: void mapViewChanged(); void locationPropertiesChanged(); void locationPermissionDenied(); void bluetoothPermissionDenied();
private: Esri::ArcGISRuntime::MapQuickView* mapView() const; QVariantMap locationProperties() const;
void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView); void setupIndoorsLocationDataSource(); void locationChangedHandler(const Esri::ArcGISRuntime::Location& loc); void changeFloorDisplay(); void requestLocationPermissionThenSetupILDS(); void requestBluetoothThenLocationPermissions(); void checkPermissions();
Esri::ArcGISRuntime::Map* m_map = nullptr; Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; Esri::ArcGISRuntime::FeatureTable* m_positioningTable = nullptr; Esri::ArcGISRuntime::ArcGISFeatureTable* m_pathwaysTable = nullptr; QVariantMap m_locationProperties; int m_currentFloor;};
#endif // SHOWDEVICELOCATIONUSINGINDOORPOSITIONING_H// [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 QtQuickimport QtQuick.Controlsimport QtQuick.Layoutsimport Esri.Samplesimport QtQuick.Dialogs
Item {
// add a mapView component MapView { id: view anchors.fill: parent
Component.onCompleted: { // Set and keep the focus on MapView to enable keyboard navigation forceActiveFocus(); }
Component.onDestruction: { model.stopLocationDisplay(); } }
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 { text: "Initializing location data source\nand retrieving user location..." // Display if there are no location properties to display visible: Object.keys(model.locationProperties).length === 0; }
Text { text: "Floor: " + model.locationProperties.floor visible: model.locationProperties.floor !== undefined } Text { text: "Position source: " + model.locationProperties.positionSource visible: model.locationProperties.positionSource !== undefined } Text { text: "Transmitter count: " + model.locationProperties.satelliteCount visible: model.locationProperties.satelliteCount !== undefined } Text { text: "Horizontal accuracy: " + (model.locationProperties.horizontalAccuracy ? model.locationProperties.horizontalAccuracy.toFixed(2) + " m" : "undefined") visible: model.locationProperties.horizontalAccuracy !== undefined } } }
// Declare the C++ instance which creates the map etc. and supply the view ShowDeviceLocationUsingIndoorPositioningSample { id: model mapView: view }
Connections { target: model function onLocationPermissionDenied() { locationPermissionDeniedDialog.open() } }
Dialog { id: locationPermissionDeniedDialog title: "Location Permission Denied" modal: true standardButtons: Dialog.Ok x: (parent.width - width) / 2 y: (parent.height - height) / 2
Text { text: "This application requires location permission." color: "white" } }
Connections { target: model function onBluetoothPermissionDenied() { bluetoothPermissionDeniedDialog.open() } }
Dialog { id: bluetoothPermissionDeniedDialog title: "Bluetooth Permission Denied" modal: true standardButtons: Dialog.Ok x: (parent.width - width) / 2 y: (parent.height - height) / 2
Text { text: "This application requires bluetooth permission." color: "white" } }}// [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]
// sample headers#include "ShowDeviceLocationUsingIndoorPositioning.h"
// ArcGIS Maps SDK headers#include "ArcGISRuntimeEnvironment.h"
// Qt headers#include <QCommandLineParser>#include <QDir>#include <QGuiApplication>#include <QQmlApplicationEngine>
// Platform specific headers#ifdef Q_OS_WIN#include <Windows.h>#endif
int main(int argc, char *argv[]){ Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setUseLegacyAuthentication(false); QGuiApplication app(argc, argv); app.setApplicationName(QString("ShowDeviceLocationUsingIndoorPositioning"));
// Use of ArcGIS location services, such as basemap styles, geocoding, and routing services, // requires an access token. For more information see // https://links.esri.com/arcgis-runtime-security-auth.
// The following methods grant an access token:
// 1. User authentication: Grants a temporary access token associated with a user's ArcGIS account. // To generate a token, a user logs in to the app with an ArcGIS account that is part of an // organization in ArcGIS Online or ArcGIS Enterprise.
// 2. API key authentication: Get a long-lived access token that gives your application access to // ArcGIS location services. Go to the tutorial at https://links.esri.com/create-an-api-key. // Copy the API Key access token.
const QString accessToken = QString("");
if (accessToken.isEmpty()) { qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" << "you to authenticate with an ArcGIS account or set the API Key property."; } else { Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setApiKey(accessToken); }
// Initialize the sample ShowDeviceLocationUsingIndoorPositioning::init();
// Initialize application view QQmlApplicationEngine engine; // Add the import Path engine.addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml"));
#ifdef ARCGIS_RUNTIME_IMPORT_PATH_2 engine.addImportPath(ARCGIS_RUNTIME_IMPORT_PATH_2);#endif
// Set the source engine.load(QUrl("qrc:/Samples/Maps/ShowDeviceLocationUsingIndoorPositioning/main.qml"));
return app.exec();}// 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.
import QtQuick.Controlsimport Esri.Samples
ApplicationWindow { visible: true width: 800 height: 600
ShowDeviceLocationUsingIndoorPositioning { anchors.fill: parent }}