Location Sources for iOS

Last updated:

  1. Developing on the new Arm-based Apple Silicon (M1) Macs requires building and running on a physical iOS device or using an iOS simulator running iOS 13.7, e.g. iPhone 11. This is a temporary limitation in Google Maps SDK for iOS, and as such also a limitation in MapsIndoors, due to the dependency to Google Maps.
  2. Note: Due to a bug in CocoaPods it is necessary to include the post_install hook in your Podfile described in the PodFile post_install wiki.

Location Sources is a new feature introduced in version 3 of MapsIndoors SDK for Android and iOS. Basically we are making it possible to register your own custom location data source, adhering to a very simple interface.

The Concepts

The central concepts in this feature are Location Sources and Location Observers, and they are best described in the following illustration:

Location Data Sources, Observers and their relation

Location Source

Maintains an array of locations and notifies its Location Observers about location and status updates.

Location Observer

Can observe a Location Source for status changes and location updates.

Creating Your own Location Source

See a demo and tutorial of this feature for iOS. Of course there is more to it than just these interfaces, but assuming that working with the actual 3rd party data is an isolated problem, the setup steps is as follows:

  1. Implement a LocationSource that pulls data from your own or a 3rd party database, API or backend and convert this data into MapsIndoors Location's
  2. Pass the Locations as updates to MapsIndoors through the interface methods of the subscribing LocationObserver's in your LocationSource implementation.

Create an implementation of the MPLocationSource interface, implementing all the required methods. When you call MPLocationObserver.onLocationsUpdate() and provide results in MPLocationSource.getLocations() you need to create instances of MPLocation's. This is done using a builder called MPLocationUpdate. See an example here:

let locationUpdate = MPLocationUpdate.init(id: 134, from: self)                         //Set unique id
locationUpdate.setType("ViewPoints") //Set type
locationUpdate.addPropertyValue("Empire State Building", forKey: MPLocationFieldName) //Set name
locationUpdate.setFloor(86) //Set floor index
locationUpdate.setPosition(CLLocationCoordinate2DMake(40.7484445, -73.9878584)) //Set position
let location = locationUpdate.location() //Generate location

While the location ID needs to be unique within your own Location Source, the ID does not need to be unique across all Location Sources.

When you have implemented all methods of your Location Source, you must register the source using the static method MapsIndoors.register(). The following example adds the MapsIndoors default location source as well:


IOS Demo and Tutorial for Location Sources

A full demo example and tutorial is available here.