Show a Map
Your environment is now fully configured, and you have the necessary map platform and MapsIndoors API keys. Next you will learn how to load a map with MapsIndoors.
Please note that data in MapsIndoors is loaded asynchronously. This results in behavior where data might not have finished loading if you call methods accessing it immediately after initializing MapsIndoors. Best practice is to set up listeners
or delegates
to inform of when data is ready. Please be aware of this when developing using the MapsIndoors SDK.
Lets start by setting up a simple app with a stateful map widget to contain the app.
First add the app to your main and import mapsindoors
Now we can create the stateful widget, we require a mapsindoors API key when constructing the map, to ensure the map is only linked to a single mapsindoors instance.
Now we can add the Map to our App
Initialize MapsIndoors
We start by loading 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 initState
method of your apps State
that displays the Google map, Ensure that the loadMapsIndoors
callback returns before accessing other MapsIndoors
methods.
If you are not a customer you can use this demo MapsIndoors API key d876ff0e60bb430b8fabb145
.
Initialize MapsIndoorsWidget
We now want to add all the data we get by initializing MapsIndoors
to our map. This is done by initializing MapsIndoorsWidget
onto the map. MapsIndoorsWidget
is used as a layer between the map and MapsIndoors.
First add the MapsIndoorsWidget
to the build hierarchy, in this example it is placed in the body of a Scaffold
, but it can be placed anywhere, just ensure there is enough space to use the map comfortably.
Then create a OnMapReadyListener
method to handle the callback from initializing MapsIndoorsWidget
:
Expected result:
See the full example of the app here: main.dart
Last updated