尝试遍历包含多个项目的列表
问题
我正在使用folium把坐标映射到地图上,我的坐标存储在一个列表里,比如这样:
[[51.52765, -0.1322611111111111], [53.54326944444444, -2.633125]].
现在,当我告诉folium从这个列表中映射一个坐标时,我必须这样指定:
folium.Marker(all_coords[1]).add_to(m) #[1] = the first set of coordinates from my list.
我的列表里有很多坐标,为了把它们全部打印出来,我必须这样做:
folium.Marker(all_coords[1]).add_to(m) #[1] = the first set of coordinates from my list.
folium.Marker(all_coords[2]).add_to(m) #[2] = the second set of coordinates from my list.
folium.Marker(all_coords[3]).add_to(m) #[3] = the third set of coordinates from my list.
folium.Marker(all_coords[4]).add_to(m) #[4] = the fourth set of coordinates from my list.
folium.Marker(all_coords[5]).add_to(m) #[5] = the fifth set of coordinates from my list.
我该如何让folium一个一个地读取我列表中的所有项目呢?
任何帮助都很感谢,谢谢 :)
相关问题:
- 暂无相关问题
1 个回答
1
没错,@roganjosh说得非常对。你想要实现的功能可以通过 Python 的 for
循环或者 while
循环来完成。
在这两者中,for
循环是最好的选择,因为它的循环变量是自动定义的。
所以,你可以通过以下方式来遍历列表,而不是使用索引:
for i in all_coords:
folium.Marker(i).add_to(m)
这个内容在这里也有清楚的展示。