Demetri Pananos
Demetri Pananos

Reputation: 7394

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

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.

Upvotes: 9

Views: 14546

Answers (3)

Joshua Roy
Joshua Roy

Reputation: 33

Try the following, which doesn't need FeatureGroup, and achieves (i) multiple markers, (ii) custom icon for each markers simultaneously.

for index, row in data.iterrows():
    custom_icon = folium.features.CustomIcon('path/to/image',icon_size=(50, 50))
    folium.Marker([row['data'],row['data']],icon=custom_icon).add_to(map)

Credits to @jimiclapton answer here.

Upvotes: 0

Collin Reinking
Collin Reinking

Reputation: 431

I create a function to add an individual points and then use DataFrame.apply() to run every row through the function.

Here is are some examples in a notebook.

Upvotes: 3

Muhammad Haseeb Khan
Muhammad Haseeb Khan

Reputation: 965

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

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

Now open the test.html file in browser and check the markers

Upvotes: 10

Related Questions