Add marker in Google Maps - Flutter
To add a list of simple markers, first create a list of markers:
List<Marker> _markers = <Marker>[];
Then add Marker to this list:
_markers.add( Marker( markerId: MarkerId('SomeId'), position: LatLng(38.123,35.123), infoWindow: InfoWindow( title: 'The title of the marker' ) ) );
Consider that in infoWindow
you can also add subtitle and other stuff.Finally add the google map widget:
GoogleMap( initialCameraPosition: CameraPosition( target: LatLng(38.9647,35.2233), zoom: 9.0, ), mapType: MapType.normal, markers: Set<Marker>.of(_markers), onMapCreated: (GoogleMapController controller) { _controller.complete(controller); }, )
First of all create a map of markers as follows:
Map<MarkerId, Marker> markers = <MarkerId, Marker>{MarkerId('marker_id_1'):Marker(markerId: MarkerId('marker_id_1'),position: LatLng(30.0444, 31.235),infoWindow: InfoWindow(title: 'marker_id_1', snippet: '*'),onTap: () { //_onMarkerTapped(markerId); print('Marker Tapped');},onDragEnd: (LatLng position) { print('Drag Ended');}, )};
Then add googleMap anywhere you want as follows
GoogleMap( mapType: MapType.normal, //initialCameraPosition: cairo, markers: Set<Marker>.of(markers.values), //onMapCreated: (GoogleMapController controller) { // _controller.complete(controller); //}, )