bpillon / google_maps_cluster_manager

Simple Flutter clustering library for Google Maps
https://pub.dev/packages/google_maps_cluster_manager
MIT License
121 stars 94 forks source link

Multiple marker inside marker builder #71

Closed Pify closed 1 month ago

Pify commented 1 month ago

Is there any way that we can use multiple marker on this lib ? i have tried but so far it only use 1 marker at a time. For example i want to make a black marker for store location with disability accessibility and red marker for store location without disability accesibility.

Any help would be appreciated.

abhlabs commented 1 month ago

I do basically the same thing, and it works fine. I actually have three different colors, based on the specific characteristics of the location. So, individual markers will have whatever marker color you establish for them. But when they're clustered, you won't see the individual markers, you see the cluster marker, which will have it's own color.

Pify commented 1 month ago

@abhlabs can you share how you achieve that different marker ? what i want is exactly as you described and do you use a variable inside model class to define if this location is green marker or blue marker and so on ? i have tried using a boolean value called isAccesible inside my model class but i get only 1 color when the marker builder executed

abhlabs commented 1 month ago

Create two markers in your class constructor or some other convenient spot in your code:

final greenMarker = BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueGreen);
final redMarker = BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueRed);

Then when you create the markers, assign either the red or green marker based on some status value:

            final marker = Marker(
              markerId:   // whatever you're using now
              icon: bShowGreenMarker ? greenMarker : redMarker, 
              position: LatLng(myLatitude!, myLongitude!),
              infoWindow: InfoWindow(
                title: "Title",
                snippet: "Snippet"
              ),
            );

This has nothing to do with clustering, if you can get this to work in a project without clustering, then it should work with clustering too. Good luck!