onDrag event for folium marker

Hi everyone ! I have a folium map with draggable markers and I would like to call some sort of “onDrag” event whenever a marker is dragged to save its new coordinates somewhere. However I have read many posts and could not find a solution.

I’ve tried using the on_change callback of the folium map, and then access the markers’ positions from map._children, but the position there is not updated. I’ve also seen a few examples of custom components using streamlit components but it was always a new leaflet map, which could not be used with other streamlit folium elements, which I would need. I would rather need a DraggableMarker class with a “onDrag” function argument.

What is the right way to achieve this ? Thank you !

Welcome to the community and thanks for your thoughtful question! :blush: Unfortunately, as of now, Streamlit-Folium does not support capturing marker drag events (like “onDrag”) or updating marker positions in real-time via callbacks. The on_change callback in Streamlit-Folium is only triggered by Streamlit widget changes, not by direct map interactions such as dragging markers. Accessing marker positions from map._children won’t reflect live updates, since Folium itself is static and doesn’t provide bi-directional communication for marker drags in Streamlit apps. This limitation is discussed in several community threads and is a known gap in the current integration between Folium and Streamlit components.

If you need true interactivity (e.g., capturing drag events and updating coordinates), you would need to build a custom Streamlit component using Leaflet.js directly, which allows for JavaScript event handling, but this means you can’t use Folium’s Python API for those markers. There is no built-in DraggableMarker class with an “onDrag” callback in Streamlit-Folium or Folium for Streamlit. For now, the only workaround is to use a custom component or wait for future updates that might add this feature. If you have a minimum reproducible example or repo, please share it so others can help brainstorm! Community members, feel free to jump in if you’ve found a creative workaround.

Sources: