Live Data in Practice
In this tutorial you will learn to work with Live Data / Real Time Data in MapsIndoors. It is recommended that you read the Live Data Introduction before continueing. It is also recommended that you read Getting Started to see how to setup a MapView and initialize MapsIndoors. To make this example work, you need a valid MapsPeople API key that allows access to live data. Also, don't forget to enable your accessible live data in the domainType variable in the toggleLiveData()
function e.g.
MPLiveDomainType.availability
MPLiveDomainType.occupancy
MPLiveDomainType.co2
MPLiveDomainType.temperature
MPLiveDomainType.humidity
MPLiveDomainType.count
MPLiveDomainType.position
In this example we will use the occupancy and position live data.
Firstly, create a class LiveDataController
that inherits from UIViewController
.
Add buttons for toggling subscriptions, one button for Live Position Updates and one for Live Occupancy Updates.
Add a method setupLiveDataButtons()
setting up buttons that enables/disables the subscriptions.
Add a method toggleLiveData()
that does the actual toggling of Live Data for a button based on the buttons isSelected
flag. Swap current selected state for button. If the flag is true and the button is selected, call the MPMapControl.enableLiveData()
method with the given Domain Type. We will also call a startFlash()
method that should make the button flash. More on this later. If the flag is false and the button is not selected, call the MPMapControl.disableLiveData()
method with the given Domain Type. Similarly we will call a stopFlash()
method that should stop the button flash. In this example, we choose to have a customized rendering of Live Data, so we provide a Handler instance that gets the updated Locations. We will get to that later.
Define an Objective-C method togglePosition()
that will receive events from your positionButton
. In this method create a position
Topic Criteria and call togglePosition
with the button and the Topic Criteria.
Define an Objective-C method toggleOccupancy()
that will receive events from your occupancyButton
. In this method create a occupancy
Topic Criteria and call togglePosition
with the button and the Topic Criteria.
Inside viewDidLoad()
, also request a building and go to this building on the map.
As an example, you can set up your buttons in your viewDidLoad() method. You can also set if up elsaware if thats your wish.
Inside viewDidLoad()
method, call setupLiveDataButtons()
arrange the map view and the buttons in stackviews.
Optionally, when you leave this controller, unsubscribe all Live Update Topics.
Earlier we called some non-existing methods, startFlash()
and stopFlash()
on a UIButton
. We will create these methods now. Create an extension for UIButton
and add the methods startFlash()
and stopFlash()
that creates and adds an animation layer that manipulates with the opacity of the button over time.
Expected Result
Last updated