简体   繁体   English

我可以在Folium地图上添加一系列标记吗?

[英]Can I add a sequence of markers on a Folium map?

Suppose I had a list, or pandas series, or latitude longitude pairs. 假设我有一个列表,或熊猫系列,或纬度经度对。 With Folium, I can plot markers for a single pair of coordinates using 使用Folium,我可以使用一对坐标绘制标记

coords = [46.8354, -121.7325]
map_4 = folium.Map(location=[46.8527, -121.7649], tiles='Stamen Terrain',
                   zoom_start=13)
folium.Marker(location=coords).add_to(map_4)

But when I try to pass a list of list, nothing is plotted. 但是当我尝试传递列表列表时,没有绘制任何内容。 I could loop through a list of lists and plot the markers, but I am wondering if I can just pass an argument and have several markers plotted. 我可以遍历列表列表并绘制标记,但我想知道我是否可以通过参数并绘制几个标记。

I create a function to add an individual points and then use DataFrame.apply() to run every row through the function. 我创建了一个函数来添加单个点,然后使用DataFrame.apply()来运行该函数的每一行。

Here is are some examples in a notebook. 以下是笔记本中的一些示例。

You can do in this way: 你可以这样做:

map = folium.Map(location = [lat, lng], zoom_start = 4, tiles = "Mapbox bright")
feature_group = folium.FeatureGroup("Locations")

for lat, lng, name in zip(lat_lst, lng_lst, name_lst):
    feature_group.add_child(folium.Marker(location=[lat,lon],popup=name))

map.add_child(feature_group)

You can also create an html file from it to see whether markers are been added or not 您还可以从中创建一个html文件,以查看是否添加了标记

map.save(outfile = "test.html")

Now open the test.html file in browser and check the markers 现在在浏览器中打开test.html文件并检查标记

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM