Skip to content Skip to sidebar Skip to footer

How To Setcenter() Leaflet Map In Flutter

I'm working on leaflet map in flutter. I built marker generator in order to make them move dynamically. I have a button to make the map center on my determined coordinate. This is

Solution 1:

You have to pass a MapController to your Flutter FlutterMap widget and in your onPressed trigger the .move() method of the controller.

The following code lets you move from the initial center to the eiffel tower, when you click the FAB. Just init your map on app start or whenever you want to.

MapController_mapController=MapController();Widget_initMap(BuildContextcontext){returnStack(children:<Widget>[newFlutterMap(mapController:_mapController,options:MapOptions(minZoom:_minzoom,maxZoom:_maxzoom,center:LatLng(mylatitude,mylongitude),),layers: [
            newTileLayerOptions(urlTemplate:'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
                subdomains: ['a', 'b', 'c']),
            newMarkerLayerOptions(markers:_generateMarker(context)),
          ]
         ),Align(alignment:Alignment.bottomRight,child:Padding(padding:EdgeInsets.all(20.0),child:newFloatingActionButton(onPressed:(){_mapController.move(LatLng(48.8587372,2.2945457),13);},child:Icon(Icons.gps_fixed),),),),],);}

Post a Comment for "How To Setcenter() Leaflet Map In Flutter"