【问题标题】:Flutter and google_maps_flutter - add listener for "my location" button click (setOnMyLocationButtonClickListener?)Flutter 和 google_maps_flutter - 为“我的位置”按钮单击添加侦听器(setOnMyLocationButtonClickListener?)
【发布时间】:2021-06-08 11:38:43
【问题描述】:

我创建了一个使用 Google 地图的 Flutter 应用。它获取用户的位置并以该点为中心。当用户四处走动时,相机会跟随它,但前提是用户自己没有手动移动相机(_userMovedMap = 0)。一旦他们移动了地图,它将不再跟随他们......

@override
Widget build(BuildContext context) {
  return MaterialApp(
    home: Scaffold(
      appBar: AppBar(
    ),
    body: Listener(
      onPointerMove: (e) {
        _userMovedMap = true;
      },
      child: GoogleMap(
        onMapCreated: _onMapCreated,
        myLocationButtonEnabled: true,
        myLocationEnabled: true,
        initialCameraPosition: CameraPosition(
          target: _center,
          zoom: _zoom,
        ),
      ),
     ),
    ),
  );
}

这是位置更新监听器,如果“_userMovedMap”为假,它也会告诉相机移动:

Geolocator.getPositionStream().listen((Position _newLocation) {

  //update position with new location data
  setState(() {
    _center = LatLng(_newLocation.latitude, _newLocation.longitude);
    //Move camera to center of location if !_userMovedMap
    if (!_userMovedMap) moveCamera();
  });
});

...这一切都很好。

但我想听听用户点击通用“我的位置”按钮(地图右上角显示的标准谷歌按钮)。该按钮可以做它应该做的(将相机动画到当前位置),但我也希望它再次将“_userMovedMap”重置为false。 据我所知,这与“setOnMyLocationButtonClickListener”有关,但 Google Maps Flutter 小部件无法识别它。

谁能帮忙?

谢谢

【问题讨论】:

    标签: flutter google-maps


    【解决方案1】:

    我找不到答案 - 我认为目前不可能。在以后的 googlemaps 插件更新中,这似乎是一个“严重”的请求,但路线图上没有任何内容。 因此,我制作了自己的位置按钮。

    【讨论】:

      猜你喜欢
      • 2015-07-31
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-02
      • 2011-08-21
      • 2017-06-18
      相关资源
      最近更新 更多