Switch branches/tags
Find file History
amirh Control the GoogleMap options with widget parameters. (#961)
The current Google Maps API was completely controller based (it was
designed before the platform views support).
Now that the GoogleMap is a widget, we are re-designing the API
around the GoogleMap widget.

This PR removes the public GoogleMapOptions class, and moves the map
options to be widget parameters. When the widget is rebuilt we compute
the options delta and send an update over the method channel.

The `initialCameraPosition` parameter was moved out of the
GoogleMapOptions Android and iOS implementations as we do not update
it when the map options are updated.

Additional API tweaks in this change:
  * Make `initialCameraPosition` a required parameter for the `GoogleMap`
  * Don't require an onMapCreated parameter for `GoogleMap`.
Latest commit 5f9affc Dec 7, 2018


Google Maps for Flutter (Developers Preview)

pub package

A Flutter plugin that provides a Google Maps widget.

Developers Preview Status

The plugin relies on Flutter's new mechanism for embedding Android and iOS views. As that mechanism is currently in a developers preview, this plugin should also be considered a developers preview.

Known issues are tagged with the platform-views and/or maps labels.

To use this plugin on iOS you need to opt-in for the embedded views preview by adding a boolean property to the app's Info.plist file, with the key io.flutter.embedded_views_preview and the value YES.

The API exposed by this plugin is not yet stable, and we expect some breaking changes to land soon.


To use this plugin, add google_maps_flutter as a dependency in your pubspec.yaml file.

Getting Started

Get an API key at https://cloud.google.com/maps-platform/.


Specify your API key in the application manifest android/app/src/main/AndroidManifest.xml:

<manifest ...
  <application ...
    <meta-data android:name="com.google.android.geo.API_KEY"
               android:value="YOUR KEY HERE"/>


Specify your API key in the application delegate ios/Runner/AppDelegate.m:

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GMSServices provideAPIKey:@"YOUR KEY HERE"];
  [GeneratedPluginRegistrant registerWithRegistry:self];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];

Opt-in to the embedded views preview by adding a boolean property to the app's Info.plist file with the key io.flutter.embedded_views_preview and the value YES.


You can now add a GoogleMap widget to your widget tree.

The map view can be controlled with the GoogleMapController that is passed to the GoogleMap's onMapCreated callback.

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() {
    home: Scaffold(
      appBar: AppBar(title: const Text('Google Maps demo')),
      body: MapsDemo(),

class MapsDemo extends StatefulWidget {
  State createState() => MapsDemoState();

class MapsDemoState extends State<MapsDemo> {

  GoogleMapController mapController;

  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(15.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
            child: SizedBox(
              width: 300.0,
              height: 200.0,
              child: GoogleMap(
                onMapCreated: _onMapCreated,
            child: const Text('Go to London'),
            onPressed: mapController == null ? null : () {
                const CameraPosition(
                  bearing: 270.0,
                  target: LatLng(51.5160895, -0.1294527),
                  tilt: 30.0,
                  zoom: 17.0,

  void _onMapCreated(GoogleMapController controller) {
    setState(() { mapController = controller; });

See the example directory for a complete sample app.