google_maps_flutter_example
A new Flutter application to demonstrate how to implement flutter google maps in a flutter application and perfoem advanced tasks on it.
Adding Map To the App
-
Get an API key at https://cloud.google.com/maps-platform/.
-
Enable Google Map SDK for each platform.
- Go to Google Developers Console.
- Choose the project that you want to enable Google Maps on.
- Select the navigation menu and then select "Google Maps".
- Select "APIs" under the Google Maps menu.
- To enable Google Maps for Android, select "Maps SDK for Android" in the "Additional APIs" section, then select "ENABLE".
- To enable Google Maps for iOS, select "Maps SDK for iOS" in the "Additional APIs" section, then select "ENABLE".
- Make sure the APIs you enabled are under the "Enabled APIs" section.
-
In
android/app/src/main/AndroidManifest.xml
insideApplication tag
add your key
- In
ios/Runner/AppDelegate.swift
add the following lines
- Use the
GoogleMapsWidget.dart
inside thelib/widget
folder as normal widget and use it where you want.
Adding Custom Marker To the map
Adding normal marker
- Declare a Set of Markers that will be shown on the map
- Add the set of markers to GoogleMap widget
- Update the set of markers after the map is created in onMapCreated
- Using this function the map will be updated with the given markers on it
Customizing the markers
- Declare a BitmapDescriptor which will hold the customIcon
- Inside initState() Assign the needed png to the customIcon
- Finally add the customIcon to the marker
Map Customization (Light/Dark mode)

Prepare the map styles
- Go to https://mapstyle.withgoogle.com/
- Choose the old version of the site by choosing No thanks, take me to the old style wizard
- You will find a lot of options, play with it until you get the desired style.
- Click Finish and a pop-up will show with the json code of your style, copy it and add it as a json file in your assets folder
Don't forgot to mention it in your pubspec.yaml
You can find two styles in the project's assets folder
Adding styles to the map
- Declare Strings that will hold your style's json and a bool to control which mode is shown on the map
- In initState declare the styles
- After creating the map, set the style
- To change the style we created a button on the map using the stack widget
Drawing routes

Activating Directions API
- Go to Google Developers Console.
- Choose the project that you want to enable Google Maps on.
- Select the navigation menu and then select "Google Maps".
- Select "APIs" under the Google Maps menu.
- Enable Google Directions, select "Directions API" in the "Additional APIs" section, then select "ENABLE".
- Make sure the APIs you enabled are under the "Enabled APIs" section.
Adding route to the map
- Declare your start and end points
- Declare polyline and polylineCoordinates
- After creating the map, set the polyline
- To set polyline we send a get request to https://www.maps.googleapis.com/maps/api/directions/json with the start location, end location and the api key
- Then we translate the results to a polyline using the MapUtils
GitHub
https://github.com/heshamerfan97/flutter_google_maps_example