参数类型列表无法分配给参数类型'LatLng'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了参数类型列表无法分配给参数类型'LatLng'相关的知识,希望对你有一定的参考价值。

我如何为Flutter定义标记数组,因为position小部件的Marker属性不接受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();
  })
}
答案

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

以上是关于参数类型列表无法分配给参数类型'LatLng'的主要内容,如果未能解决你的问题,请参考以下文章