Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[google_maps_flutter] fixes #1

Merged
merged 9 commits into from
Apr 27, 2023
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.googlemapsexample">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ Future<AndroidMapRenderer?> initializeMapRenderer() async {
return _initializedRendererCompleter!.future;
}

_initializedRendererCompleter = Completer<AndroidMapRenderer?>();
final Completer<AndroidMapRenderer?> completer =
Completer<AndroidMapRenderer?>();
_initializedRendererCompleter = completer;

WidgetsFlutterBinding.ensureInitialized();

Expand All @@ -103,10 +105,10 @@ Future<AndroidMapRenderer?> 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,14 @@ class MapIdBodyState extends State<MapIdBody> {
'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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -174,9 +178,4 @@ public void setInitialCircles(Object initialCircles) {
public void setInitialTileOverlays(List<Map<String, ?>> initialTileOverlays) {
this.initialTileOverlays = initialTileOverlays;
}

@Override
public void setMapId(String mapId) {
options.mapId(mapId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,6 @@ public void setInitialTileOverlays(List<Map<String, ?>> initialTileOverlays) {
}
}

@Override
public void setMapId(String mapId) {
Log.e(TAG, "Cannot change MapId after map is initialized.");
}

private void updateInitialTileOverlays() {
tileOverlaysController.addTileOverlays(initialTileOverlays);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public PlatformView create(Context context, int id, Object args) {
Map<String, Object> params = (Map<String, Object>) 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);
Expand All @@ -54,6 +55,11 @@ public PlatformView create(Context context, int id, Object args) {
if (params.containsKey("tileOverlaysToAdd")) {
builder.setInitialTileOverlays((List<Map<String, ?>>) params.get("tileOverlaysToAdd"));
}
final Object cloudMapId = ((Map<?, ?>) options).get("cloudMapId");
if (cloudMapId != null) {
builder.setMapId((String) cloudMapId);
}

return builder.build(id, context, binaryMessenger, lifecycleProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,4 @@ interface GoogleMapOptionsSink {
void setInitialCircles(Object initialCircles);

void setInitialTileOverlays(List<Map<String, ?>> initialTileOverlays);

void setMapId(String mapId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ Future<AndroidMapRenderer?> initializeMapRenderer() async {
return _initializedRendererCompleter!.future;
}

_initializedRendererCompleter = Completer<AndroidMapRenderer?>();
final Completer<AndroidMapRenderer?> completer =
Completer<AndroidMapRenderer?>();
_initializedRendererCompleter = completer;

WidgetsFlutterBinding.ensureInitialized();

final GoogleMapsFlutterPlatform platform = GoogleMapsFlutterPlatform.instance;
(platform as GoogleMapsFlutterAndroid)
.initializeWithRenderer(AndroidMapRenderer.latest)
.then((AndroidMapRenderer initializedRenderer) =>
_initializedRendererCompleter!.complete(initializedRenderer));
completer.complete(initializedRenderer));

return _initializedRendererCompleter!.future;
return completer.future;
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ class MapIdBodyState extends State<MapIdBody> {
'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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ class MapIdBodyState extends State<MapIdBody> {
'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"),
)
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions(

options.styles = styles;

options.mapId = configuration.cloudMapId;

return options;
}

Expand Down Expand Up @@ -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<String> _mapStyleKeys = <String>{
'elementType',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down