google_maps_flutter предоставил пример добавления нескольких маркеров: разместить маркер , вы должны проверить это:
void _add() {
final int markerCount = markers.length;
if (markerCount == 12) {
return;
}
final String markerIdVal = 'marker_id_$_markerIdCounter';
_markerIdCounter++;
final MarkerId markerId = MarkerId(markerIdVal);
final Marker marker = Marker(
markerId: markerId,
position: LatLng(
center.latitude + sin(_markerIdCounter * pi / 6.0) / 20.0,
center.longitude + cos(_markerIdCounter * pi / 6.0) / 20.0,
),
infoWindow: InfoWindow(title: markerIdVal, snippet: '*'),
onTap: () {
_onMarkerTapped(markerId);
},
onDragEnd: (LatLng position) {
_onMarkerDragEnd(markerId, position);
},
);
setState(() {
markers[markerId] = marker;
});
}
ОБНОВЛЕНО:
GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: const CameraPosition(
target: LatLng(-33.852, 151.211),
zoom: 11.0,
),
// TODO(iskakaushik): Remove this when collection literals makes it to stable.
// https://github.com/flutter/flutter/issues/28312
// ignore: prefer_collection_literals
markers: Set<Marker>.of(markers.values),
),
void loc(LocationData a) {
LatLng latlng = LatLng(a.latitude, a.longitude);
final Marker marker = Marker(
markerId: MarkerId("mine"),
position: latlng,
icon: BitmapDescriptor.defaultMarker,
draggable: false,
zIndex: 1,
);
setState(() {
markers[markerId] = marker;
});
}