如何取消Google地图标记的拖动事件并将其返回到Flutter中的初始位置?

问题描述

我正在使用google_maps_flutter创建带有两种标记的Google地图。将一种标记物拖到另一种标记物上时,我想删除被拖动的标记物,然后执行功能。我能够做到。

但是,如果拖动的标记放置在错误的位置,那么我想将标记放回其原始位置。我找不到任何事件或方法来实现这一目标。该怎么办?

这是我添加标记代码

markers.add(
  Marker(
    markerId: packageMarkerId,draggable: true,icon: _unassignedOrderMarkerIcon,onTap: () {
      print('marker tapped');
    },position: LatLng(coordinates.latitude,coordinates.longitude),onDragEnd: (LatLng latLng) {
      double newLat =
        double.parse(latLng.latitude.toStringAsFixed(1));
      double newLong =
        double.parse(latLng.longitude.toStringAsFixed(1));
      for (var user in usersDocuments) {
        Map<String,dynamic> userLocation =
          user.data['user_location'];
      if (userLocation != null) {
        if (newLat == userLocation['latitude'] &&
              newLong == userLocation['longitude']) {
           print('Equal coords: $latLng');
           markers.removeWhere((element) {
             print('Marker removed!');
             return element.markerId == packageMarkerId;
           });
           setState(() {
             _markers = markers;
           });
           return;
        } else {
           print('Unequal coords,not merged!');
           print(userLocation['latitude']);
           print(userLocation['longitude']);
           return;
         }
       }
      }
    },),);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)