AssertionError:如果该元素不在图中,则无法渲染此元素

问题描述 投票:1回答:1

我写了以下代码:

import folium
map = folium.Marker(location=[80, -100], zoom_start=6, tiles="Mapbox Bright")
fg = folium.FeatureGroup(name="My map")
fg.add_child(folium.Marker(location=[80, -100], popup="Marker Here", icon=folium.Icon(color="green")))

map.save("Map.html")

而且我一直收到此错误消息:

Traceback (most recent call last):
  File "c:/Users/king/Desktop/applications/mapping/maps.py", line 6, in <module>
    map.save("Map.html" )
  File "C:\Users\king\AppData\Local\Programs\Python\Python38-32\lib\site-packages\branca\element.py", line 169, in save
    html = root.render(**kwargs)
  File "C:\Users\king\AppData\Local\Programs\Python\Python38-32\lib\site-packages\branca\element.py", line 614, in render
    assert isinstance(figure, Figure), ('You cannot render this Element '
AssertionError: You cannot render this Element if it is not in a Figure.

我正在尝试保存我正在构建的地图的进度,并且不断显示错误消息

python folium
1个回答
0
投票

根据docsMarker应添加到Map

map = folium.Map(
        location=[80, -100],
        zoom_start=6,
        tiles="Mapbox Bright"
      )

fg = folium.FeatureGroup(name="My map")

folium.Marker(
    location=[80, -100],
    popup="Marker Here",
    icon=folium.Icon(icon='green')
).add_to(map)
© www.soinside.com 2019 - 2024. All rights reserved.