Switching Solutions
Some larger organisations may have not just multiple Venues, but also multiple Solutions in the MapsIndoors system. Therefore, it is naturally important to be able to switch between them.
At it's core, this is done simply by switching out the API key and reloading the system. However, there are a few more steps that can be done to ensure smooth transition between Solutions.
Android
Starting a Solution
To initialize MapsIndoors, do the following:
- Android v4
- iOS v4
- iOS v3
If you are looking for documentation on Android SDK v3, please see here.
- Google Maps
- Mapbox
- Java
- Kotlin
protected void onCreate(Bundle savedInstanceState) {
...
mMapView = mapFragment.getView();
MapsIndoors.load(getApplicationContext(), "YOUR_MAPSINDOORS_API_KEY", null);
mapFragment.getMapAsync(this);
...
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (mMapView != null) {
initMapControl(mMapView);
}
}
void initMapControl(View view) {
MPMapConfig mapConfig = new MPMapConfig.Builder(this, mMap, getString(R.string.google_maps_key), view, true).build();
MapControl.create(mapConfig, (mapControl, miError) -> {
mMapControl = mapControl;
if (miError == null) {
//Orient your map to where you need data to be shown. This could be done by getting the default venue through MapsIndoors and panning the camera there
}
});
}
override fun onCreate(savedInstanceState: Bundle?) {
...
MapsIndoors.load(applicationContext, "YOUR_MAPSINDOORS_API_KEY", null)
mapFragment.view?.let {
mapView = it
}
...
}
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
mapView?.let { view ->
initMapControl(view)
}
}
fun initMapControl(view: View) {
MPMapConfig mapConfig = new MPMapConfig.Builder(this, mMap, getString(R.string.google_maps_key), view, true).build();
//Creates a new instance of MapControl
MapControl.create(config) { mapControl, miError ->
if (miError == null) {
mMapControl = mapControl!!
//Orient your map to where you need data to be shown. This could be done by getting the default venue through MapsIndoors and panning the camera there
}
}
}
- Java
- Kotlin
protected void onCreate(Bundle savedInstanceState) {
...
MapsIndoors.load(getApplicationContext(), "YOUR_MAPSINDOORS_API_KEY", null);
...
}
void initMapControl(View view) {
MPMapConfig mapConfig = new MPMapConfig.Builder(this, mMapboxMap, mMapView, getString(R.string.mapbox_access_token),true).build();
//Creates a new instance of MapControl
MapControl.create(mapConfig, (mapControl, miError) -> {
mMapControl = mapControl;
if (miError == null) {
//Orient your map to where you need data to be shown. This could be done by getting the default venue through MapsIndoors and panning the camera there
}
});
}
override fun onCreate(savedInstanceState: Bundle?) {
...
MapsIndoors.load(applicationContext, "YOUR_MAPSINDOORS_API_KEY", null)
...
}
fun initMapControl(view: View) {
val config = MPMapConfig.Builder(this, mMap, mapView, getString(R.string.mapbox_access_token),true).build()
//Creates a new instance of MapControl
MapControl.create(config) { mapControl, miError ->
if (miError == null) {
//Orient your map to where you need data to be shown. This could be done by getting the default venue through MapsIndoors and panning the camera there
}
}
}
When you load your initial Solution, it's beneficial to initialize MapsIndoors properly, to ensure it's easy to switch Solutions later if needed.
- Google Maps
- Mapbox
func setupMapsIndoors(mapsIndoorsAPIKey: String, googleMapsAPIKey: String) async throws {
// Orient your map to where you need data to be shown.
// This can e.g. be done by pointing the camera to a specific location (shown below)
// or getting the default venue after MapsIndoors is loaded and panning the camera there.
let camera = .camera(withLatitude: 57.057964, longitude: 9.9504112, zoom: 20)
self.mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
self.view = self.mapView
// Initialize the MPMapConfig with the GMSMapView
self.mapConfig = MPMapConfig(gmsMapView: self.mapView, googleApiKey: googleMapsAPIKey)
try await MPMapsIndoors.shared.load(apiKey: mapsIndoorsAPIKey)
self.mapControl = MPMapsIndoors.createMapControl(mapConfig: mapConfig)
}
func setupMapsIndoors(mapsIndoorsAPIKey: String, mapboxAccessToken: String) async throws {
// Set up the Mapbox map view
let mapInitOptions = MapInitOptions(resourceOptions: ResourceOptions(accessToken: mapboxAccessToken))
self.mapView = MapView(frame: self.view.bounds, mapInitOptions: mapInitOptions)
self.view = self.mapView
// Orient your map to where you need data to be shown.
// This can e.g. be done by pointing the camera to a specific location (shown below)
// or getting the default venue after MapsIndoors is loaded and panning the camera there.
let centerCoordinate = CLLocationCoordinate2D(latitude: 57.057964, longitude: 9.9504112, zoom: 20)
self.mapView.mapboxMap.setCamera(to: CameraOptions(center: centerCoordinate, zoom: 20))
// Initialize the MPMapConfig with the Mapbox MapView
self.mapConfig = MPMapConfig(mapBoxView: mapView, accessToken: mapboxAccessToken)
try await MPMapsIndoors.shared.load(apiKey: mapsIndoorsAPIKey)
self.mapControl = MPMapsIndoors.createMapControl(mapConfig: mapConfig)
}
When you load your initial Solution, it's beneficial to initialize MapsIndoors properly, to ensure it's easy to switch Solutions later if needed.
You don't have to initialize positionProvider
or enableLiveData
. This is only needed if you use third-party Positioning such as Cisco DNA Spaces or MapsIndoors' Live Data function.
func setupMapsIndoors(mapsIndoorsAPIKey: String, googleMapsAPIKey: String) {
map = GMSMapView(frame: CGRect.zero)
view = map
mapControl = MPMapControl(map: map!)
MapsIndoors.provideAPIKey(mapsIndoorsAPIKey, googleAPIKey: googleMapsAPIKey)
MapsIndoors.synchronizeContent { error in
// Orient your map to where you need data to be shown. This can e.g. be done by pointing the camera to a specific location or getting the default venue through MapsIndoors and panning the camera there
self.map?.camera = .camera(withLatitude: 57.057964, longitude: 9.9504112, zoom: 20)
// Setup needed services
MapsIndoors.positionProvider = MyPositionProvider()
MapsIndoors.positionProvider?.startPositioning(nil)
self.mapControl?.enableLiveData(MPLiveDomainType.occupancy, handler: self)
}
}
Switching Solutions
You switch Solutions by changing the active API key.
We recommend creating your own function to call in the future for this purpose, like the example here with switchSolution()
:
- Android v4
- iOS v4
- iOS v3
If you are looking for documentation on Android SDK v3, please see here.
- Google Maps
- Mapbox
- Java
- Kotlin
protected void switchSolution() {
mMapControl.onDestroy();
MapsIndoors.load(getApplication(), "YOUR_SECONDARY_API_KEY", null);
mMapView.getMapAsync(this);
}
private fun switchSolution() {
mMapControl.onDestroy()
MapsIndoors.load(applicationContext, "YOUR_SECONDARY_API_KEY", null)
mMapView.getMapAsync(this)
}
- Java
- Kotlin
mMapControl.onDestroy();
MapsIndoors.load(getApplicationContext(), "YOUR_SECONDARY_API_KEY", null);
initMapControl(mMapBoxMap, mMapView);
mMapControl.onDestroy()
MapsIndoors.load(applicationContext, "YOUR_SECONDARY_API_KEY", null)
initMapControl(mMapBoxMap, mMapView)
To switch Solutions you just set up MapsIndoors with a new MapsIndoors API key by calling setupMapsIndoors
with your new desired API key.
We recommend creating your own function to call in the future for this purpose, like the example here with switchSolution()
:
- Google Maps
- Mapbox
func switchSolution() {
// Setup MapsIndoors anew
setupMapsIndoors(mapsIndoorsAPIKey: "YOUR_SECONDARY_API_KEY", googleMapsAPIKey: "YOUR_GOOGLE_API_KEY")
}
func switchSolution() {
// Setup MapsIndoors anew
setupMapsIndoors(mapsIndoorsAPIKey: "YOUR_SECONDARY_API_KEY", mapboxAccessToken: "YOUR_MAPBOX_ACCESS_TOKEN")
}
To switch Solutions, you first need to ensure that all your existing instances are closed down safely. Once this is done, you can use setupMapsIndoors
to restart with your new desired API key.
We recommend creating your own function to call in the future for this purpose, like the example here with switchSolution()
:
func switchSolution() {
// Close existing services in use as they are solution specific
MapsIndoors.positionProvider?.stopPositioning(nil)
MapsIndoors.positionProvider = nil
MPLiveDataManager.sharedInstance().unsubscribeAll()
// Setup MapsIndoors anew
map = nil
mapControl = nil
setupMapsIndoors(mapsIndoorsAPIKey: "YOUR_SECONDARY_API_KEY", googleMapsAPIKey: "YOUR_GOOGLE_API_KEY")
}