迭代标记Google Flutter地图

El *_*bre 7 google-maps dart flutter

我正在尝试迭代新的Google Flutter Map中的标记。

我使用Web服务检索坐标数组,然后迭代元素并获取具有纬度和经度的索引。

for (int i = 0; i < list.length; i++) {
 mapController.addMarker(MarkerOptions(position:  list[0].values.elementAt(i)))));
}
Run Code Online (Sandbox Code Playgroud)

和地图选项。

GoogleMapController mapController;

GoogleMap(
     onMapCreated: (GoogleMapController mapController) {
          mapController = mapController;         
     },
     options: GoogleMapOptions(
          mapType: MapType.satellite,
          myLocationEnabled :true,
          cameraPosition: CameraPosition(
          target: LatLng(40.347022, -3.750381), zoom: 5.0),
    ),
),
Run Code Online (Sandbox Code Playgroud)

我想mapController应该采用我放入for循环中的坐标,但是不起作用。控制台返回

方法“ addMarker”在null上被调用。

所以问题是,如何使用Google Flutter Map包动态添加多个标记?

我也尝试了这个简单的代码并且可以工作,因此添加标记时发生了错误。

  GoogleMapController mapController;

    GoogleMap(
                  onMapCreated: (GoogleMapController mapController) {
                    mapController = mapController;
                    mapController.addMarker(MarkerOptions(
                      position:LatLng(40.347022, -3.750381),          
                      infoWindowText: InfoWindowText("Title", "Content"),
                      //icon:
                    ));
                     mapController.addMarker(MarkerOptions(
                      position:LatLng(43.321871, -3.006887),          
                      infoWindowText: InfoWindowText("Title", "Content"),
                      //icon:
                    ));

                  },
                  options: GoogleMapOptions(
                    mapType: MapType.satellite,
                    myLocationEnabled :true,
                    cameraPosition: CameraPosition(
                        target: LatLng(40.347022, -3.750381), zoom: 5.0),
                  ),
                ),
Run Code Online (Sandbox Code Playgroud)

更新2

我找到了这个示例代码。这正是我想要的,但我无法重复此代码,请返回此错误

https://github.com/gerryhigh/Flutter-Google-Maps-Demo/blob/master/lib/venues.dart

NoSuchMethodError:在null上调用了getter'className'。

tom*_*wyr -1

在第一个示例中,GoogleMapController参数和局部变量具有相同的名称,因此基本上,局部变量会被隐藏,并且您将函数参数值分配给自身。重命名这两个之一应该可以解决该问题。