Search code examples
pythonfolium

Folium - Map doesn't appear


I try to get map through Folium but only thing I can see is marker on blank page. I'd like to know where is problem lies, in explorer or coding.

map.py

import folium

map = folium.Map(location = [46.20, 6.144], zoom_start=6, tiles="Mapbox Bright")

fg = folium.FeatureGroup(name="My Map")
fg.add_child(folium.Marker(location=[40.12, 10.1], popup="Hi I'am a Marker", 
icon=folium.Icon(color='green')))
map.add_child(fg)

map.save("Map1.html")

Solution

  • There is a problem with the tiles name "Mapbox Bright". It seems that this kind of tiles is not supported by Folium/Leaflet anymore (without token). If you use one of the other tiles that are listed in the documentation, it will work :

    import folium
    
    m = folium.Map(location = [46.20, 6.144], zoom_start=6, tiles="OpenStreetMap")
    
    fg = folium.FeatureGroup(name="My Map")
    fg.add_child(folium.Marker(location=[40.12, 10.1], popup="Hi I'am a Marker", 
    icon=folium.Icon(color='green')))
    m.add_child(fg)
    m
    

    It is better not to use map for the name of your map because it is a Python function and you are shadowing it (so you can't use it anymore).