fluttergoogle-maps-markersgoogle-maps-flutterfluttermap

How to trigger a function when user taps on google map markers - Flutter


How can we execute a function for example _markerPressed() in google map when user taps on a marker?

I dont want to show a popup I know its possible using infoWindow. I want to, for example open a card on screen.

enter image description here

I've tried the onTap: and onLongPress: functions but it's only working while tapping on the map not the markers.

Thank you in advance


Solution

  •  final Marker marker = Marker(
              markerId: markerId,
              position: LatLng(
                center.latitude + sin(_markerIdCounter * pi / 6.0) / 20.0,
                center.longitude + cos(_markerIdCounter * pi / 6.0) / 20.0,
              ),
              infoWindow: InfoWindow(title: markerIdVal, snippet: '*'),
    
              onTap: (){
                 //TODO: show your card
               },
    
              onDragEnd: (LatLng position) => _onMarkerDragEnd(markerId, position),
              onDrag: (LatLng position) => _onMarkerDrag(markerId, position),
            );
    

    https://github.com/flutter/plugins/blob/master_archive/packages/google_maps_flutter/google_maps_flutter/example/lib/place_marker.dart