Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:如何从谷歌地图中清除多段线_Flutter_Dart_Google Maps Flutter - Fatal编程技术网

Flutter 颤振:如何从谷歌地图中清除多段线

Flutter 颤振:如何从谷歌地图中清除多段线,flutter,dart,google-maps-flutter,Flutter,Dart,Google Maps Flutter,我用下面的代码创建了一个带有标记和多段线的GoogleMaps小部件 一切正常,除了当我在两个坐标之间绘制一条多段线,然后尝试删除它时,该多段线不会被删除(至少不会永久删除)。当我使用以下方法尝试删除旧多段线并添加新多段线时,我得到两条多段线: _polyLine.clear() _polyLine.remove("id") polylines.removeWhere((m) => m.polylineId.value == 'polyId$_randPolyId') 它被删除,然后在新

我用下面的代码创建了一个带有标记和多段线的GoogleMaps小部件

一切正常,除了当我在两个坐标之间绘制一条多段线,然后尝试删除它时,该多段线不会被删除(至少不会永久删除)。当我使用以下方法尝试删除旧多段线并添加新多段线时,我得到两条多段线:

_polyLine.clear()
_polyLine.remove("id")
polylines.removeWhere((m) => m.polylineId.value == 'polyId$_randPolyId')
它被删除,然后在新的基础上再次添加。结果如下图所示:

。。。
void setPolylines()异步{
列表结果=等待_polylinePoints.GetRouteBeween坐标(
_Googleapkey,
_当前位置。纬度,
_当前位置。经度,
_目的地纬度,
_destinationLocation.longitude).catchError((onError){
打印(“\n\n\n网络问题期间可能发生错误\n\n\n”);
});
如果(结果!=null){
打印(“结果不为空”);
if(result.isNotEmpty){
结果.forEach((点对齐点){
_多段线坐标。添加(
LatLng(点、纬度、点、经度)
);
});
_isLoadingData=false;
_多段线。添加(多段线)(
宽度:5,
polylineId:polylineId('polyId$和polyId'),
颜色:
颜色。来自argb(255、40、122、198),
点:_多段线坐标
));
}
}
notifyListeners();
}
...

在绘制新路径之前,需要清除多段线坐标

多段线坐标。清除();//在检查结果值之前调用此函数

polylineCoordinates.clear();
    if(result != null){
    print("Results not null");
   if(result.isNotEmpty){
      result.forEach((PointLatLng point){
         _polylineCoordinates.add(
            LatLng(point.latitude,point.longitude)
         );
      });

  }
}

是的,很有效!
...
void setPolylines() async {
   List<PointLatLng> result = await _polylinePoints.getRouteBetweenCoordinates(
   _googleAPIKey,
   _currentLocation.latitude,
   _currentLocation.longitude,
   _destinationLocation.latitude,
   _destinationLocation.longitude).catchError((onError){
     print("\n\n\n An Error Occured Possibly dure to network issues\n\n\n");
   });

  if(result != null){
    print("Results not null");
   if(result.isNotEmpty){
      result.forEach((PointLatLng point){
         _polylineCoordinates.add(
            LatLng(point.latitude,point.longitude)
         );
      });
       _isLoadingData = false;
      _polylines.add(Polyline(
        width: 5, 
        polylineId: PolylineId('polyId$_randPolyId'),
        color:
        Color.fromARGB(255, 40, 122, 198), 
        points: _polylineCoordinates
        ));
  }
  }
  notifyListeners();
}
...
polylineCoordinates.clear();
    if(result != null){
    print("Results not null");
   if(result.isNotEmpty){
      result.forEach((PointLatLng point){
         _polylineCoordinates.add(
            LatLng(point.latitude,point.longitude)
         );
      });

  }
}