【问题标题】:Argument type List<LatLng> can't be assigned to parameter type 'LatLng'参数类型 List<LatLng> 不能分配给参数类型“LatLng”
【发布时间】:2019-12-14 10:32:35
【问题描述】:

如何为 Flutter 定义一组标记,因为 Marker 小部件的 position 属性不接受 LatLng 点列表。我该如何解决这个问题?

final List<LatLng> _markerLocations = [
    LatLng(3.082519, 101.592201),
    LatLng(3.083355, 101.589653),
    LatLng(3.08171, 101.587507),
    LatLng(3.082519, 101.592201),
  ];
void _initMarkers() async {
    Marker marker = Marker(
      markerId: MarkerId('loop_route'),
      position: _markerLocations
    );
    setState(() {
      markers.add(_markerLocations);
    });
}
void _onMapCreated(GoogleMapController controller) {
  setState((){
    mapController = controller;
    _initMarkers();
  })
}

【问题讨论】:

    标签: flutter


    【解决方案1】:

    Marker 采用LatLng 的实例,因为一个Marker 只能有一个LatLng。一个标记只能在地图中的一个位置。

    您需要创建尽可能多的标记LatLng

    你必须这样做:

    _markerLocations.forEach((LatLng latLong){
        markers.add(Marker(
          markerId: MarkerId('loop_route'),
          position: latLong
        ));
      });
    

    通过替换:

     markers.add(_markerLocations);
    

    【讨论】:

    猜你喜欢
    • 2022-10-07
    • 2022-08-13
    • 2020-03-22
    • 2020-03-22
    • 2020-05-28
    • 2021-07-04
    • 2021-12-10
    • 2021-10-24
    • 2022-11-05
    相关资源
    最近更新 更多