View on GitHub Sample viewer app

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

  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

IndoorsLocationDataSourceCreator.cpp IndoorsLocationDataSourceCreator.cpp IndoorsLocationDataSourceCreator.h ShowDeviceLocationUsingIndoorPositioning.cpp ShowDeviceLocationUsingIndoorPositioning.h ShowDeviceLocationUsingIndoorPositioning.qml main.cpp main.qml
// [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));
}