0

I want to insert a live url link into my marker's popup in Python Folium but I don't know what class and code I need to use. my code is a simple one:

folium.Marker(location[i], popup="www.dingsbums.lu").add_to(marker_cluster)

I just want the url (here 'www.dingsbums.lu') to be a link, not string...

5
  • What have you tried because unless you add a Python code attempt your question will be closed.
    – gene
    Commented Jan 27, 2021 at 14:43
  • You need to properly format your HTML. Commented Jan 28, 2021 at 18:00
  • @s.k: Thank you for your comment...I followed your instruction and now my code seems like this: url=folium.Html('<a href="w3schools.com"></a>') folium.Marker(location[i], popup=url).add_to(marker_cluster) but now I have just an empty popup! Any idea...?
    – Parsley
    Commented Jan 30, 2021 at 11:12
  • Do not blindly copy7paste stuff, make sure you understand what href does. Look at the URL.This should answer your question; gis.stackexchange.com/questions/185897/… Commented Jan 30, 2021 at 11:48
  • @s.k: Thank you for your comment...I followed the link instructions but nothing is changed in my map. Can you help to find and solve the problem?
    – Parsley
    Commented Jan 30, 2021 at 16:28

1 Answer 1

1

This code snippet should do the job. You can then simply replace the URL and the text to be displayed (it can actually be the same as the URL) with the ones you want.
E.g. "<a href=https://www.dingsbums.lu>https://www.dingsbums.lu</a>"

import folium
m = folium.Map(location=[49.611622, 6.131935], zoom_start=16,)

tooltip = "Click me!"

marker = folium.Marker(
    [49.61068, 6.13127],
    popup="<a href=https://fr.wikipedia.org/wiki/Place_Guillaume_II>Place Guillaume II</a>",
    tooltip=tooltip
)

marker.add_to(m)

Then, when displaying the map m it should show you the following, with a clickable URL in the popup:

Resulting map Notice that the URL is shown on the bottom left of the browser when the mouse is over the corresponding link in the popup.

More information can be found on the folium documentation: https://python-visualization.github.io/folium/quickstart.html

And how the href attribute actually works can be discovered here with code samples: https://www.w3schools.com/tags/att_href.asp

1
  • 1
    Thanks a lot. You did it well and now the problem is solved. It seems the problem of my code relied on two issues: first, I'd used "' more than needed. Secondly,It's necessary to give marker's arguments explicitly.
    – Parsley
    Commented Jan 31, 2021 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.