I am trying a simple project where I want to show a map of locations and when I click on a marker, new markers will pop up that are tied with that location.
I am new to this and I have tried some basic implementations. The idea was to have it create a marker at [37,-100] when I click on the initial marker at [37,-95], but nothing happened.
m = folium.Map(location=[37.0902, -95.7129], zoom_start=4)
folium.Marker([37, -95]).add_to(m)
js_click_handler = """
<script>
function onMapClick(e) {
folium.Marker([37, -100]).add_to(m)
}
document.getElementById('map').on('popupopen', onMapClick);
</script>
"""
map_html = f'<div id="map">{m.get_root().render()}</div>'
display(HTML(map_html + js_click_handler))
m.save("map.html")
New contributor
Logan Becker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.