skip to Main Content
    GoogleMap(
        mapType: MapType.normal,
        initialCameraPosition: CameraPosition(
          target: geocode!,
          zoom: 14,
        ),
        onMapCreated: (GoogleMapController controller) async {
          googleMapControllerCompleter.complete(controller);
        },
        compassEnabled: true,
        myLocationEnabled: true,
        onTap: (v) {},
        markers: <--->),

        ------
        List<Marker> dumA = [];
        markerGroupA = Set<Marker>.of(dumA);
        List<Marker> dumB = [];
        markerGroupB = Set<Marker>.of(dumB);

I have a list of these two marker groups. How can I display them on markers: ? I don’t want to put them into one Set<Marker> if possible. I was able to do that but I lost the code and can’t find a way to do it.

2

Answers


  1. A Set<T> has a method union that merges 2 Sets.
    You can find the dart documentation here : https://api.flutter.dev/flutter/dart-core/Set/union.html

    GoogleMap(
      mapType: MapType.normal,
      initialCameraPosition: CameraPosition(
        target: geocode!,
        zoom: 14,
      ),
      onMapCreated: (GoogleMapController controller) async {
        googleMapControllerCompleter.complete(controller);
      },
      compassEnabled: true,
      myLocationEnabled: true,
      onTap: (v) {},
      markers: markerGroupA.union(markerGroupB),
    )
    
    Login or Signup to reply.
  2. Use addAll function as below

    GoogleMap(
            mapType: MapType.normal,
            initialCameraPosition: CameraPosition(
              target: geocode!,
              zoom: 14,
            ),
            onMapCreated: (GoogleMapController controller) async {
              googleMapControllerCompleter.complete(controller);
            },
            compassEnabled: true,
            myLocationEnabled: true,
            onTap: (v) {},
            markers: markerGroupA),
    
            ------
            List<Marker> dumA = [];
            markerGroupA = Set<Marker>.of(dumA);
            List<Marker> dumB = [];
            markerGroupB = Set<Marker>.of(dumB);
            markerGroupA.addAll(markerGroupB);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search