1

I'm using the latest version of google_maps_flutter, and I noticed that this code is now showing a deprecation warning:

if (_mapStyle != null) {
  mapController.setMapStyle(_mapStyle);
}

I used this to apply a custom JSON map style after the map was created.
But now setMapStyle is marked as deprecated, and the documentation doesn't clearly show the new recommended way.
I tried looking for an alternative like applyMapStyle or other methods on GoogleMapController, but none seems to replace it.

1 Answer 1

2

Use the mapStyle parameter on the GoogleMap widget:

final String mapStyleJson = '''[ ... your JSON ... ]''';

GoogleMap(
  initialCameraPosition: const CameraPosition(
    target: LatLng(10.0, 76.0),
    zoom: 14,
  ),
  mapStyle: mapStyleJson,
  onMapCreated: (controller) {
    mapController = controller;
  },
)

You can check the full example in the official Google Maps Flutter package.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.