Skip to content

Commit 89a3b61

Browse files
author
Chiogros
committed
Add MapController to center view on current user location when triggers geolocation button
1 parent 3151a81 commit 89a3b61

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/src/map.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class CustomMap extends StatefulWidget {
2121

2222
class _CustomMapState extends State<CustomMap> {
2323
LatLng _position = LatLng(45.172044, 5.734129);
24+
final double _zoom = 13.0;
2425
final PopupController _popupLayerController = PopupController();
26+
final MapController _mapController = MapController();
2527
List<Place> _places = <Place>[];
2628

2729
Future<String> _downloadPlaces() async {
@@ -144,6 +146,7 @@ class _CustomMapState extends State<CustomMap> {
144146
currentPos.latitude,
145147
currentPos.longitude
146148
);
149+
_mapController.move(_position, _zoom);
147150
} on TimeoutException {
148151
// nothing
149152
} on PermissionDeniedException {
@@ -178,9 +181,10 @@ class _CustomMapState extends State<CustomMap> {
178181
],
179182
),
180183
body: FlutterMap(
184+
mapController: _mapController,
181185
options: MapOptions(
182186
center: _position,
183-
zoom: 13.0,
187+
zoom: _zoom,
184188
),
185189
children: [
186190
TileLayerWidget(

0 commit comments

Comments
 (0)