如何使用Flutter / Dart添加标记点击/点击地图?
我刚刚开始研究颤振/飞镖。来自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
});
}
我看了看互联网的所有地方,发现了很多添加标记的示例,但没有单击地图(例如,示例1,示例2)。google_maps_flutter插件对此没有提及。是否可以通过点击地图添加标记,或者这仍然不可用?
提前致谢。
回答:
该插件终于添加了onTap该属性GoogleMap类。
final ArgumentCallback<LatLng> onTap例:
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),
  ));
});
}
以上是 如何使用Flutter / Dart添加标记点击/点击地图? 的全部内容, 来源链接: utcz.com/qa/414781.html
