ASH
ASH

Reputation: 20342

How can we get tooltips and popups to show in Folium

I am trying to get a tooltip and/or a popup to show on a map. When I zoom in, this is all that I see.

enter image description here

Here is the code that I am testing.

import folium
import requests
from xml.etree import ElementTree
from folium import plugins

m = folium.Map(location=[40.6976701, -74.2598704], zoom_start=10)
m.save('path')
for lat,lon,name,tip in zip(df_final['Latitude(DecDeg)'], df_final['Latitude(DecDeg)'], df_final['Market Description'], df_final['Project Description']):
    folium.Marker(location=[lat,lon], tooltip = tip, popup = name)
m.add_child(cluster)
m

I feel like I'm missing a library, or some such thing. Any idea why this is not working correctly?

Upvotes: 7

Views: 12077

Answers (1)

furas
furas

Reputation: 143001

It seems you forgot to use .add_to(m) to add it to map

folium.Marker(...).add_to(m)

or

marker = folium.Marker(...)
marker.add_to(m)

Minimal working code:

import folium
import webbrowser  # open file in webbrowser

m = folium.Map(location=[40.6976701, -74.2598704], zoom_start=10)

marker = folium.Marker(location=[40.6976701, -74.2598704], 
                       tooltip='<b>Stackoverflow</b><br><br>2021.01.01', 
                       popup='<h1>Happy&nbsp;New&nbsp;Year!</h1><br><br>www:&nbsp;<a href="https://stackoverflow.com">Stackoverflow.com</a><br><br>date:&nbsp;2021.01.01')
marker.add_to(m)

m.save('map.html')

webbrowser.open('map.html')  # open file in webbrowser

enter image description here

Upvotes: 9

Related Questions