如何使用Flutter / Dart添加标记点击/点击地图?

cub*_*Guy 1 google-maps dart flutter

我刚刚开始研究颤振/飞镖。来自HTML5 / Javascript,我想知道这等效于:

google.maps.event.addListener(map, 'click', function(event) {
 placeMarker(event.latLng);
});

function placeMarker(location) {
var marker = new google.maps.Marker({
    position: location, 
    map: map
});
Run Code Online (Sandbox Code Playgroud)

}

我看了看互联网的所有地方,发现了很多添加标记的示例,但没有点击地图(例如,示例1,示例2)。google_maps_flutter插件对此没有提及。是否可以通过点击地图来添加标记,或者这仍然不可用?

提前致谢。

cub*_*Guy 5

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

final ArgumentCallback<LatLng> onTap
Run Code Online (Sandbox Code Playgroud)

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),
  ));
});
Run Code Online (Sandbox Code Playgroud)

}