Search code examples
fluttergoogle-mapsflutter-web

How to add multiple markers in Google map with Flutter Web?


How can I add multiple markers by tap/click the map in Google map with Flutter Web? All of the tutorial were using google_maps_flutter not google_maps_flutter_web.


Solution

  • try this,

    //list of markers 
    final Set<Marker> markers = new Set();
    
    markers.add(Marker( //add first marker
      markerId: MarkerId(showLocation.toString()),
      position: showLocation, //position of marker
      infoWindow: InfoWindow( //popup info 
        title: 'My Custom Title ',
        snippet: 'My Custom Subtitle',
      ),
      icon: BitmapDescriptor.defaultMarker, //Icon for Marker
    ));
    
    markers.add(Marker( //add second marker
      markerId: MarkerId(showLocation.toString()),
      position: LatLng(27.7099116, 85.3132343), //position of marker
      infoWindow: InfoWindow( //popup info 
        title: 'My Custom Title ',
        snippet: 'My Custom Subtitle',
      ),
      icon: BitmapDescriptor.defaultMarker, //Icon for Marker
    )); 
    
    GoogleMap( //Map widget from google_maps_flutter package
      markers: markers, //markers to show on map
    )