【发布时间】:2021-11-24 04:24:44
【问题描述】:
我正在尝试在谷歌地图中添加多个标记,但是一旦我调用该函数,只会显示最后一个标记。我错过了什么?
我读到here 说我必须传递一个动态markerId,我想我已经这样做了,但由于某种原因我无法获得第一个标记,总是最后一个。
注意:这不是错字类型的问题 - 如果我删除了 last 标记,则会显示 first 标记。所以它必须与用last一覆盖first标记的函数有关:
void Markers() async {
var firstPath = "img/first.png";
final Uint8List firstIcon = await getBytesFromAsset(firstPath, 50);
var lastPath = "img/last.png";
final Uint8List lastIcon = await getBytesFromAsset(lastPath, 50);
_listmarkers = Set<Marker>();
_listmarkers.add(Marker(
markerId: MarkerId(_navigationList.first.userId.toString()),
position: LatLng(_navigationList.first.latitude,
_navigationList.first.longitude),
icon: BitmapDescriptor.fromBytes(firstIcon),
));
_listmarkers.add(Marker(
markerId: MarkerId(_navigationList.last.userId.toString()),
position: LatLng(_navigationList.last.latitude,
_navigationList.last.longitude),
icon: BitmapDescriptor.fromBytes(lastIcon),
));
setState(() {});
}
void createMap() {
if (_navigationList.isNotEmpty) {
_postsController.add(1);
LatLngBounds bound = boundsFromLatLngList(_navigationList);
Markers();
}
}
【问题讨论】:
标签: flutter google-maps dart google-maps-markers