Marker Layer
You can add single point features - including arbitrary widgets - to maps using MarkerLayer and Markers.
No more image only markers! Unlike other π popular mapping libraries, we allow usage of any widget as the marker.

Markers on a rotated mapExcessive use of markers may create performance issues.
Consider using a clustering plugin to merge nearby markers together, reducing the work that needs to be done when rendering: Marker Clustering.
Size
The height and width parameters are required to enable the positioning and culling of the markers to work correctly.
The marker child will be sized to these parameters, which default to 30 logical pixels. If the child will change size, set the size to the largest size and control the size of the child within a widget which allows it to be smaller than the constraints set.
Alignment & Counter-Rotation
By default, the marker's child is centered over the point, and will always remain upright relative to the North when the map is rotated.
This can be changed using alignment and rotate.
To keep the child upright relative to the screen (counter-rotate it compared to any map rotation), set rotate to true.
To change the pivot point for the counter-rotation and the alignment of the child to the point, set the alignment accordingly.
For example:
These parameters can also be set directly on the MarkerLayer to change the default for all of its markers.
Handling State
Often, marker children do not have their own internal state (they are StatelessWidgets). However, some use-cases may require them to be stateful.
Markers are culled when they go offscreen, and the marker child is not built when culled. Therefore, any widget state is lost when culling.
When multiple of the same marker is visible at once, across multiple worlds, the marker child is built multiple times. Therefore, the widget states are not synchronized, and any keys in the child subtree may not be unique.
Marker children should not be StatefulWidgets, and keys should not be used in the child's tree. Instead, the state should be detached and moved up in the tree, using an inherited approach. For example, a state management package, or Flutter's built-in options like InheritedWidget or ValueNotifier - remember that FlutterMap.children can contain widgets wrapped around layers like this.
Then, some map should be kept linking a unique property of the marker (its point could be suitable and easily accessed in most dynamic marker layer systems) to its state. The marker child can then lookup this state.
For example:
Handling Gestures
If you need to, for example, handle taps and presses on your marker's child, it's easy! Just wrap the child in something like a GestureDetector, or a button.
If you need to be able to drag the marker, check out the community maintained plugin 'flutter_map_dragmarker'. Alternatively if you need more control, build it yourself. Because of the way flutter_map handles gestures, the following workaround may be required to allow the marker to capture the necessary gesture events:
Use a
RawGestureDetectorand customPanGestureRecognizerthan declares victory in the gesture arena. For example:
Last updated
Was this helpful?