Search code examples
pythonfolium

folium.Marker does not does decode properly


I have a folium map called imap. I have created a string object called test_mark which is a string 'Coruña-Torre de Hércules: Presión: 964.4hPa'

test_mark = 'Coruña-Torre de Hércules: Presión: 964.4hPa'
folium.Marker(location=(43.30,-8.30),popup= test_mark, icon= folium.Icon()).add_to(imap)

When I check the marker on the map, what I get is 'Coruña-Torre de Hércules: Presión: 964.4hPa'. I guess it might be some kind of encoding problem, but I can not figure out how to solve it.

Thanks in advance


Solution

  • You can add charset=windows-1252 through meta tag for Spanish language such as

    import folium
    
    lt = 43.30
    ln = -8.30
    
    imap = folium.Map(location=[lt,ln],zoom_start=19)
    
    test_mark  = '<head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></head>'
    test_mark += '<strong>Coruña-Torre de Hércules: Presión: 964.4hPa<strong>'
    
    imap.get_root().html.add_child(folium.Element(test_mark))
    
    folium.Marker(location=[lt,ln],
                  popup= test_mark,
                  icon= folium.Icon()).add_to(imap)
    
    imap.save('map.html')