diff --git a/packages/google_maps_flutter/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml b/packages/google_maps_flutter/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml index 7d7d8ed4cdaf..815074bfad96 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml +++ b/packages/google_maps_flutter/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml @@ -1,4 +1,5 @@ - + diff --git a/packages/google_maps_flutter/google_maps_flutter/example/ios/Podfile b/packages/google_maps_flutter/google_maps_flutter/example/ios/Podfile index b690cc71379e..b6bc7dedde1e 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/ios/Podfile +++ b/packages/google_maps_flutter/google_maps_flutter/example/ios/Podfile @@ -1,5 +1,5 @@ -# Uncomment this line to define a global platform for your project -# platform :ios, '11.0' +# Global platform version is set to 12 for this example project to support cloud-based maps styling +platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart index a75a6c937556..ce85eb5db77d 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart @@ -94,7 +94,9 @@ Future initializeMapRenderer() async { return _initializedRendererCompleter!.future; } - _initializedRendererCompleter = Completer(); + final Completer completer = + Completer(); + _initializedRendererCompleter = completer; WidgetsFlutterBinding.ensureInitialized(); @@ -103,10 +105,10 @@ Future initializeMapRenderer() async { if (mapsImplementation is GoogleMapsFlutterAndroid) { mapsImplementation.initializeWithRenderer(AndroidMapRenderer.latest).then( (AndroidMapRenderer initializedRenderer) => - _initializedRendererCompleter!.complete(initializedRenderer)); + completer.complete(initializedRenderer)); } else { - _initializedRendererCompleter!.complete(null); + completer.complete(null); } - return _initializedRendererCompleter!.future; + return completer.future; } diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/map_map_id.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/map_map_id.dart index a8cbe369260d..fa9e0bf2feac 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/map_map_id.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/map_map_id.dart @@ -108,21 +108,14 @@ class MapIdBodyState extends State { 'Press to use specified map Id', ), )), - if (Platform.isAndroid) + if (Platform.isAndroid && + _initializedRenderer != AndroidMapRenderer.latest) Padding( padding: const EdgeInsets.all(10.0), child: Text( 'On Android, Cloud-based maps styling only works with "latest" renderer.\n\n' 'Current initialized renderer is "${_getInitializedsRendererType()}".'), ), - if (Platform.isIOS) - const Padding( - padding: EdgeInsets.all(10.0), - child: - Text('On iOS, cloud based map styling works only if iOS platform ' - 'version 12 or above is targeted in project Podfile. ' - "Run command 'pod update GoogleMaps' to update plugin"), - ) ]; return Column( diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java index 36bb4fad39be..78c7dc2428c6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java @@ -377,10 +377,6 @@ static void interpretGoogleMapOptions(Object o, GoogleMapOptionsSink sink) { if (buildingsEnabled != null) { sink.setBuildingsEnabled(toBoolean(buildingsEnabled)); } - final Object cloudMapId = data.get("cloudMapId"); - if (buildingsEnabled != null) { - sink.setMapId(toString(cloudMapId)); - } } /** Returns the dartMarkerId of the interpreted marker. */ diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java index fae03c050c7a..fa82b77743d2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java @@ -55,6 +55,10 @@ void setInitialCameraPosition(CameraPosition position) { options.camera(position); } + public void setMapId(String mapId) { + options.mapId(mapId); + } + @Override public void setCompassEnabled(boolean compassEnabled) { options.compassEnabled(compassEnabled); @@ -174,9 +178,4 @@ public void setInitialCircles(Object initialCircles) { public void setInitialTileOverlays(List> initialTileOverlays) { this.initialTileOverlays = initialTileOverlays; } - - @Override - public void setMapId(String mapId) { - options.mapId(mapId); - } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index f7e419ff63de..a57cd1a34c97 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -871,11 +871,6 @@ public void setInitialTileOverlays(List> initialTileOverlays) { } } - @Override - public void setMapId(String mapId) { - Log.e(TAG, "Cannot change MapId after map is initialized."); - } - private void updateInitialTileOverlays() { tileOverlaysController.addTileOverlays(initialTileOverlays); } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapFactory.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapFactory.java index ffa2412f9c42..0bc2cf48a266 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapFactory.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapFactory.java @@ -34,7 +34,8 @@ public PlatformView create(Context context, int id, Object args) { Map params = (Map) args; final GoogleMapBuilder builder = new GoogleMapBuilder(); - Convert.interpretGoogleMapOptions(params.get("options"), builder); + final Object options = params.get("options"); + Convert.interpretGoogleMapOptions(options, builder); if (params.containsKey("initialCameraPosition")) { CameraPosition position = Convert.toCameraPosition(params.get("initialCameraPosition")); builder.setInitialCameraPosition(position); @@ -54,6 +55,11 @@ public PlatformView create(Context context, int id, Object args) { if (params.containsKey("tileOverlaysToAdd")) { builder.setInitialTileOverlays((List>) params.get("tileOverlaysToAdd")); } + final Object cloudMapId = ((Map) options).get("cloudMapId"); + if (cloudMapId != null) { + builder.setMapId((String) cloudMapId); + } + return builder.build(id, context, binaryMessenger, lifecycleProvider); } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java index e3308a8b3350..17f0d970a4ef 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java @@ -55,6 +55,4 @@ interface GoogleMapOptionsSink { void setInitialCircles(Object initialCircles); void setInitialTileOverlays(List> initialTileOverlays); - - void setMapId(String mapId); } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/example/lib/main.dart b/packages/google_maps_flutter/google_maps_flutter_android/example/lib/main.dart index 35d9dffa8005..dfb95306037f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/example/lib/main.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/example/lib/main.dart @@ -92,7 +92,9 @@ Future initializeMapRenderer() async { return _initializedRendererCompleter!.future; } - _initializedRendererCompleter = Completer(); + final Completer completer = + Completer(); + _initializedRendererCompleter = completer; WidgetsFlutterBinding.ensureInitialized(); @@ -100,7 +102,7 @@ Future initializeMapRenderer() async { (platform as GoogleMapsFlutterAndroid) .initializeWithRenderer(AndroidMapRenderer.latest) .then((AndroidMapRenderer initializedRenderer) => - _initializedRendererCompleter!.complete(initializedRenderer)); + completer.complete(initializedRenderer)); - return _initializedRendererCompleter!.future; + return completer.future; } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_map_id.dart b/packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_map_id.dart index 091933b7d455..984e32a8ea5a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_map_id.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_map_id.dart @@ -109,12 +109,13 @@ class MapIdBodyState extends State { 'Press to use specified map Id', ), )), - Padding( - padding: const EdgeInsets.all(10.0), - child: Text( - 'On Android, Cloud-based maps styling only works with "latest" renderer.\n\n' - 'Current initialized renderer is "${_getInitializedsRendererType()}".'), - ), + if (_initializedRenderer != AndroidMapRenderer.latest) + Padding( + padding: const EdgeInsets.all(10.0), + child: Text( + 'On Android, Cloud-based maps styling only works with "latest" renderer.\n\n' + 'Current initialized renderer is "${_getInitializedsRendererType()}".'), + ), ]; return Column( diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios/Podfile b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios/Podfile index 39d60ec703f5..d2f013d2f6d2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios/Podfile +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios/Podfile @@ -1,5 +1,5 @@ -# Uncomment this line to define a global platform for your project -# platform :ios, '11.0' +# Global platform version is set to 12 for this example project to support cloud-based maps styling +platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/lib/map_map_id.dart b/packages/google_maps_flutter/google_maps_flutter_ios/example/lib/map_map_id.dart index d3c98041c0f4..037bafd8a350 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/lib/map_map_id.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/lib/map_map_id.dart @@ -85,13 +85,6 @@ class MapIdBodyState extends State { 'Press to use specified map Id', ), ), - ), - const Padding( - padding: EdgeInsets.all(10.0), - child: - Text('On iOS, cloud based map styling works only if iOS platform ' - 'version 12 or above is targeted in project Podfile. ' - "Run command 'pod update GoogleMaps' to update plugin"), ) ]; diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m index 91079691f7aa..c5b1c00d9233 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m @@ -81,8 +81,9 @@ - (instancetype)initWithFrame:(CGRect)frame GMSMapView *mapView; #if defined(__IPHONE_12_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_12_0 - if (args[@"options"][@"cloudMapId"]) { - GMSMapID *mapID = [GMSMapID mapIDWithIdentifier:args[@"options"][@"cloudMapId"]]; + NSString *cloudMapId = args[@"options"][@"cloudMapId"]; + if (cloudMapId) { + GMSMapID *mapID = [GMSMapID mapIDWithIdentifier:cloudMapId]; mapView = [GMSMapView mapWithFrame:frame mapID:mapID camera:camera]; } else { mapView = [GMSMapView mapWithFrame:frame camera:camera]; diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart index 0e3474c60c70..ca404992a1c9 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart @@ -85,6 +85,8 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions( options.styles = styles; + options.mapId = configuration.cloudMapId; + return options; } @@ -122,14 +124,6 @@ gmaps.MapOptions _applyInitialPosition( return options; } -gmaps.MapOptions _applyMapId( - String? mapId, - gmaps.MapOptions options, -) { - options.mapId = mapId; - return options; -} - // The keys we'd expect to see in a serialized MapTypeStyle JSON object. final Set _mapStyleKeys = { 'elementType', diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart index e41aabc147b9..a659fb218803 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart @@ -160,7 +160,6 @@ class GoogleMapController { _lastMapConfiguration, _lastStyles); // Initial position can only to be set here! options = _applyInitialPosition(_initialCameraPosition, options); - options = _applyMapId(_lastMapConfiguration.cloudMapId, options); // Create the map... final gmaps.GMap map = _createMap(_div, options);