5

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?

ASH
  • 20,759
  • 19
  • 87
  • 200
  • is this code working without error message ? Where do you create `cluster` ? What is in `cluster` Or maybe you should assign Marker to variable and use `m.add_child(marker)` inside `for`-loop – furas Dec 31 '20 at 22:34
  • i check some documents and it seems it has to be `folium.Marker(...).add_to(m)` and you don't have `.add_to(m)` – furas Dec 31 '20 at 23:23

1 Answers1

7

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

furas
  • 134,197
  • 12
  • 106
  • 148
  • Yeah, that makes sense. I made the change that you recommended, re-ran it, and now I get this error message: NameError: name 'cluster' is not defined I ran this 'pip install cluster'; everything finished off fine. I re-started the kernel, re-ran the whole process, and again, I got the error: NameError: name 'cluster' is not defined I'm working in a Jupyter Notebook. – ASH Jan 03 '21 at 17:00
  • and what is `cluster`? Why do you use this name ? if it has to be some variable then create it. If it is module then `import` it. – furas Jan 03 '21 at 17:18
  • I asked Google about `cluster` and `folium` and found example which uses code `cluster = folium.FeatureGroup(name='cluster')` but you don't have it. https://stackoverflow.com/a/49419357/1832058 – furas Jan 03 '21 at 17:23
  • It works fine now. Thanks for sticking with me on this one!! Appreciate it!! – ASH Jan 05 '21 at 03:31