如何使用Flutter / Dart添加标记点击/点击地图? [英] How to add a marker tap/click on map using Flutter/Dart?

查看:492
本文介绍了如何使用Flutter / Dart添加标记点击/点击地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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, 'click', function(event) {
 placeMarker(event.latLng);
});

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

}

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

I've looked all around the internet, and I found many examples of adding markers, but not on map click.(e.g. Example 1, Example 2). The google_maps_flutter plugin doesn't mention anything about this yet. Is it possible to add the marker by tapping the map, or is this something that's still not available?

预先感谢。

推荐答案

plugin 最终为 GoogleMap 类添加了 onTap 属性。

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

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添加标记点击/点击地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆