I am reading Chapter 11 of the Flutter Cookbook – Second Edition by Simone Alessandria. I follow the following steps:
-
Create a new Flutter app, and call it map_recipe.
-
flutter pub add google_maps_flutter
-
I obtained Google Maps API key from here.
-
Open the
android/app/src/main/AndroidManifest.xml
file in your project.
Add the following line under the icon launcher icon, in the application node:android:icon="@mipmap/ic_launcher">
-
Set the minSdkVersion in the
android/app/build.gradle
file:android {
defaultConfig {
minSdkVersion 20
}
}
But how to do it for Web?
The full code can be found on the author’s GitHub
2
Answers
For web, you should provide your google key in the
web/index.html
. It should be inside of the head tag.Documentation – https://developers.google.com/maps/flutter-package/config#web
The steps you have followed is for adding Google maps to the Android platform.
To add Google Maps to your flutter web project, you would need to use the google_maps_flutter_web package and it since it is endorsed by the google_maps_flutter package, you just need to add your API key to the
head
yourweb/index.html
file.Add this script to your
head
tag: