Show a Map
Your environment is now fully configured, and you have the necessary Google Maps and MapsIndoors API keys. Next you will learn how to load a map with MapsIndoors.
Show a Map with MapsIndoors
Initialize MapsIndoors
We start by initializing MapsIndoors
. MapsIndoors
is used to get and store all references to MapsIndoors-specific data. This includes access to all MapsIndoors-specific geodata.
Place the following initialization code in the onCreate
method in the MapsActivity
that displays the Google map. You should also assign the mapFragment
view to a local variable, as we will use this later to initialize MapControl
inside the onCreate
, after it has been created:
override fun onCreate(savedInstanceState: Bundle?) {
...
MapsIndoors.load(applicationContext, "YOUR_MAPSINDOORS_API_KEY", null)
mapFragment.view?.let {
mapView = it
}
...
}
If you do not have your own key, you can use this demo MapsIndoors API key: 02c329e6777d431a88480a09
.
Initialize MapsControl
We now want to add all the data we get by initializing MapsIndoors
to our map. This is done by initializing MapControl
onto the map. MapControl
is used as a layer between the map provider and MapsIndoors.
Start by creating an initMapControl
method which is used to initiate the MapControl
and assign it to mMap:
private 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!!
//Enable live data on the map
enableLiveData()
//No errors so getting the first venue (in the white house solution the only one)
val venue = MapsIndoors.getVenues()?.currentVenue
venue?.bounds?.let {
runOnUiThread {
//Animates the camera to fit the new venue
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(LatLngBoundsConverter.toLatLngBounds(it), 19))
}
}
}
}
}
In your onMapReady
callback function, assign the mMap
variable with the GoogleMap
you get from the callback and call the initMapControl
method with the mMapView
you assigned in the onCreate
to set up a Google map with MapsIndoors Venues, Buildings and Locations. For Mapbox you can simple call initMapControl inside your onCreate
:\
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
mapView?.let { view ->
initMapControl(view)
}
}
Expected result:

See the full example of MapsActivity here: MapsActivity.kt
The Mapbox examples can be found here: MapsActivity.kt
Last updated
Was this helpful?