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.
/// The widget that will contain the map
class Map extends StatefulWidget {
const Map({super.key, required this.apiKey});
final String apiKey;
@override
State<Map> createState() => _MapState();
}
class _MapState extends State<Map> {
@override
Widget build(BuildContext context) {
throw UnimplementedError();
}
}
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.
class _MapState extends State<Map> {
@override
void initState() {
super.initState();
loadMapsIndoors(widget.apiKey).then((error) {
// if no error occured during loading, then we can start using the SDK
if (error == null) {
// do stuff like fetching locations
}
});
}
}
If you are not a customer you can use this demo MapsIndoors API key d876ff0e60bb430b8fabb145.
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:
Place the following initialization code in the initState method of your apps State that displays the Google map, Ensure that the callback returns before accessing other MapsIndoors methods.
Initialize MapsIndoorsWidget
We now want to add all the data we get by initializing MapsIndoors to our map. This is done by initializing onto the map. MapsIndoorsWidget is used as a layer between the map and MapsIndoors.