删除添加到地图的最后一个标记
removing the last marker added to map
我正在开发一个应用程序,我必须在地图上标记很多地方,我想删除最后添加到地图上的标记。我使用的方法是清除所有标记
这是我用来添加标记的方法
void _setMarkers(LatLng point) {
final String markerIdVal = 'marker_id_$_markerIdCounter';
_markerIdCounter++;
setState(() {
print(
'Marker | Latitude: ${point.latitude} Longitude: ${point.longitude}');
_markers.add(
Marker(
markerId: MarkerId(markerIdVal),
position: point,
),
);
});
}
这是撤消点方法
Widget _undomarker() {
return FloatingActionButton.extended(
onPressed: () {
//Remove marker
setState(() {
_markers.clear();
});
},
icon: Icon(Icons.undo),
label: Text('Undo point'),
backgroundColor: Colors.orange,
);
}
Widget _undomarker() {
return FloatingActionButton.extended(
onPressed: () {
//Removes the last marker only
setState(() {
_markers.remove( _markers.last );
});
},
icon: Icon(Icons.undo),
label: Text('Undo point'),
backgroundColor: Colors.orange,
);
我正在开发一个应用程序,我必须在地图上标记很多地方,我想删除最后添加到地图上的标记。我使用的方法是清除所有标记
这是我用来添加标记的方法
void _setMarkers(LatLng point) {
final String markerIdVal = 'marker_id_$_markerIdCounter';
_markerIdCounter++;
setState(() {
print(
'Marker | Latitude: ${point.latitude} Longitude: ${point.longitude}');
_markers.add(
Marker(
markerId: MarkerId(markerIdVal),
position: point,
),
);
});
}
这是撤消点方法
Widget _undomarker() {
return FloatingActionButton.extended(
onPressed: () {
//Remove marker
setState(() {
_markers.clear();
});
},
icon: Icon(Icons.undo),
label: Text('Undo point'),
backgroundColor: Colors.orange,
);
}
Widget _undomarker() {
return FloatingActionButton.extended(
onPressed: () {
//Removes the last marker only
setState(() {
_markers.remove( _markers.last );
});
},
icon: Icon(Icons.undo),
label: Text('Undo point'),
backgroundColor: Colors.orange,
);