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 sampleWhen 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 worksIndoorsLocationDataSource
with the positioning feature table (stored with the map) and the pathways feature table after both tables are loaded.IndoorsLocationDataSource
to the map view's location display.Navigation
to zoom to and follow the user's location.LocationDisplay::start()
. Device location will appear on the display as a blue dot and update as the user moves throughout the space.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 informationbeacon, BLE, blue dot, Bluetooth, building, facility, GPS, indoor, IPS, location, map, mobile, navigation, site, transmitter
Sample CodeShowDeviceLocationUsingIndoorPositioning.cpp ShowDeviceLocationUsingIndoorPositioning.cpp ShowDeviceLocationUsingIndoorPositioning.h IndoorsLocationDataSourceCreator.cpp IndoorsLocationDataSourceCreator.h ShowDeviceLocationUsingIndoorPositioning.qml
Use dark colors for code blocks Copy
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
// [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 IndoorsLocationDataSource
void 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 necessary
void 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;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4