How to add a marker tap/click on map using Flutter/Dart?

后端 未结 3 768
鱼传尺愫
鱼传尺愫 2021-01-12 16:10

I just started to take a look into flutter/dart. Coming from HTML5/Javascript, I wonder what would be an equivalent to:

google.maps.event.addListener(map, \         


        
相关标签:
3条回答
  • 2021-01-12 16:55

    you want to take the mapcontroller and use it for ex:

    **GoogleMapController controller;**
    
    **controller.onMarkerTapped.add((Marker marker){/...your code.../);**
    
    0 讨论(0)
  • 2021-01-12 16:59

    The plugin has finally added an onTap property for the GoogleMap Class.

    final ArgumentCallback<LatLng> onTap
    

    Example:

    GoogleMap(
        markers: _markers,
        initialCameraPosition: _theSecretLocation,
        onMapCreated: (GoogleMapController controller) {
          _controller.complete(controller);
        },
        onTap: _handleTap,
      ),
      ...
    
     _handleTap(LatLng point) {
    setState(() {
      _markers.add(Marker(
        markerId: MarkerId(point.toString()),
        position: point,
        infoWindow: InfoWindow(
          title: 'I am a marker',
        ),
        icon:
            BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueMagenta),
      ));
    });
    }
    
    0 讨论(0)
  • 2021-01-12 17:05
          List _markers = List.generate(10, (index) {
          Map result = results[index];
          Map location = result["geometry"]["location"];
          LatLng latLngMarker = LatLng(location["lat"], location["lng"]);
    
          return Marker(
              markerId: MarkerId("marker$index"),
              position: latLngMarker,
              onTap: () {
                         //Your code here...
                        },
              infoWindow: InfoWindow(title: result["name"],));
        });
    
       
    
    0 讨论(0)
提交回复
热议问题