【发布时间】:2019-06-02 02:48:45
【问题描述】:
我正在尝试在新的 google flutter map 中迭代标记。
我使用 Web 服务检索坐标数组,然后迭代元素并获取具有纬度和经度的索引。
for (int i = 0; i < list.length; i++) {
mapController.addMarker(MarkerOptions(position: list[0].values.elementAt(i)))));
}
还有地图选项。
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),
),
),
我认为 mapController 应该采用我放在 for 循环中的坐标,但它不起作用。控制台返回
在 null 上调用了方法“addMarker”。
所以问题是,如何使用谷歌颤振地图包动态添加多个标记?
我也试过这个简单的代码并且工作正常,所以添加标记时出现错误。
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),
),
),
更新 2
我找到了这个示例代码。这正是我想要的,但我不能重复此代码,返回此错误
https://github.com/gerryhigh/Flutter-Google-Maps-Demo/blob/master/lib/venues.dart
NoSuchMethodError:getter 'className' 在 null 上被调用。
【问题讨论】:
标签: google-maps dart flutter