我試圖在谷歌地圖中添加多個標記,但是一旦我呼叫該函式,只顯示最后一個標記。我錯過了什么?
我在這里讀到我必須傳遞一個動態markerId,我想我已經在做,但由于某種原因我無法獲得第一個標記,總是最后一個。
注意:這不是打字錯誤型別的問題 - 如果我洗掉last標記,first則會顯示標記。因此,它必須與用以下first標記覆寫標記的函式有關last:
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();
}
}
uj5u.com熱心網友回復:
最可能
_navigationList.last.userId.toString() == _navigationList.first.userId.toString()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/313503.html
