Show a map

Last updated:

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 Google Maps map with MapsIndoors.

Show a map with MapsIndoors

Initialize MapsIndoors

Place the following initialization code in the onCreate method in the activity that should display the Google map. You should also assign the mapFragment view to a variable as we will use this later to initialize MapControl:

MapView = mapFragment.getView();
MapsIndoors.initialize(getApplicationContext(), "YOUR_MAPSINDOORS_API_KEY");
MapsIndoors.setGoogleAPIKey(“YOUR_GOOGLE_API_KEY”);
MapsIndoors.initialize(applicationContext, "79f8e7daff76489dace4f9f9")
MapsIndoors.setGoogleAPIKey(getString(R.string.google_maps_key))

mapFragment.view?.let {
mapView = it
}

If you are not a customer you can use this demo MapsIndoors API key 79f8e7daff76489dace4f9f9.

In your onMapReady callback function, use the MapControl class to set up a Google map with MapsIndoors Venues, Buildings and Locations:

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

if (view != null) {
initMapControl(view);
}
}

void initMapControl(View view) {
//Creates a new instance of MapControl
mMapControl = new MapControl(this);
//Sets the Google map object and the map view to the MapControl
mMapControl.setGoogleMap(mMap, view);
//Initiates the MapControl
mMapControl.init(miError -> {
if (miError == null) {
//No errors so getting the first venue (in the white house solution the only one)
Venue venue = MapsIndoors.getVenues().getCurrentVenue();
runOnUiThread( ()-> {
if (venue != null) {
//Animates the camera to fit the new venue
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(venue.getLatLngBoundingBox(), 19));
}
});
}
});
}
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
MapsIndoors.initialize(applicationContext, "79f8e7daff76489dace4f9f9")
MapsIndoors.setGoogleAPIKey(getString(R.string.google_maps_key))

mapView?.let { view ->
initMapControl(view)
}
}

private fun initMapControl(view: View) {
//Creates a new instance of MapControl
mMapControl = MapControl(this)
//Sets the Google map object and the map view to the MapControl
mMapControl.setGoogleMap(mMap, view)
mMapControl.init { miError ->
if (miError == null) {
//No errors so getting the first venue (in the white house solution the only one)
val venue = MapsIndoors.getVenues()?.currentVenue

runOnUiThread {
//Animates the camera to fit the new venue
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(venue?.latLngBoundingBox, 19));
}
}
}
}

See the full example of MapsActivity here MapsActivity.java or MapsActivity.kt

Head to the guides to learn about event handling, searching, getting directions, display settings and more.

Next up: Search