Closed mtan11 closed 2 years ago
The switch display marker is as follows?
bool _isShowLocMarker = false;
FlutterMap(
options: MapOptions(
...
),
children: [
TileLayerWidget(
options: TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
maxZoom: 19,
),
),
if (_isShowLocMarker)
LocationMarkerLayerWidget(
plugin: LocationMarkerPlugin(
centerCurrentLocationStream:
_centerCurrentLocationStreamController.stream,
centerOnLocationUpdate: _centerOnLocationUpdate,
),
),
Positioned(
right: 20,
bottom: 80,
child: Column(
children: [
FloatingActionButton(
heroTag: null,
onPressed: () => setState(() {
_isShowLocMarker = false;
_centerCurrentLocationStreamController.close();
}),
child: Icon(
Icons.gps_off,
color: Colors.white,
),
),
SizedBox(height: 20),
FloatingActionButton(
heroTag: null,
onPressed: () {
// Automatically center the location marker on the map when location updated until user interact with the map.
setState(() {
if (!_isShowLocMarker) {
_centerCurrentLocationStreamController =
StreamController<double>();
}
_centerOnLocationUpdate =
CenterOnLocationUpdate.first;
});
// Center the location marker on the map and zoom the map to level 18.
_centerCurrentLocationStreamController.add(18);
_isShowLocMarker = true;
},
child: Icon(
Icons.my_location,
color: Colors.white,
),
),
],
)),
]
),
I want to create a button toggle get location user. How to stop showing location marker when i tap on the toggle button. Thanks for your help.