Sitemap

How to integrate Google Maps into the Flutter app

2 min readJan 19, 2023

--

Press enter or click to view image in full size
How To integrate google maps in flutter

Flutter is a popular open-source framework for building mobile apps and Google Maps is one of the most widely used mapping services in the world. Combining the two can provide a powerful tool for creating location-based apps with rich and interactive maps. In this article, we will discuss how to integrate Google Maps into a Flutter app.

First, you will need to create a Google Maps API key. This key is used to authenticate your app and allow it to access the Google Maps services. To create an API key, go to the Google Cloud Console and create a new project. Once the project is created, enable the Google Maps JavaScript API and the Google Places API for the project. Then, create an API key and enable it for the project.

Get Abdul Muhib Bhojani’s stories in your inbox

Join Medium for free to get updates from this writer.

Next, you will need to add the Google Maps package to your Flutter project. This can be done by adding the following line to your pubspec.yaml file:

dependencies:
google_maps_flutter: ^0.5.28

Once the package is added, you can start using the Google Maps widgets in your app. To display a map, you can use the GoogleMap widget. This widget takes a few parameters such as the initial camera position and the map type. For example, the following code will display a map centered on New York City with a zoom level of 12:

GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(40.748817, -73.985428),
zoom: 12,
),
mapType: MapType.normal,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
),

You can also add markers to the map, which are used to indicate specific locations. To add a marker, you can use the Marker widget. For example, the following code will add a marker to the map at the location of the Empire State Building:

Marker(
markerId: MarkerId('Empire State Building'),
position: LatLng(40.748817, -73.985428),
infoWindow: InfoWindow(
title: 'Empire State Building',
snippet: 'New York, NY',
),
onTap: () {
print('Marker tapped');
},
),

In addition to markers, you can also add other types of overlays to the map such as polygons, polylines and circles.

Another thing you can do is to customize the look of the map by applying different styles. You can use the MapStyle widget to apply a JSON style to the map. You can find many pre-built styles on the Google Maps website or you can create your own custom style using the Map Style Wizard.

In conclusion, integrating Google Maps into a Flutter app is a straightforward process that can greatly enhance the functionality and user experience of your app. With the power of Google Maps and the flexibility of Flutter, the possibilities are endless. Happy coding!

--

--