Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add a sequence of markers on a Folium map?

Tags:

python

folium

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.

like image 570
Demetri Pananos Avatar asked Feb 19 '17 17:02

Demetri Pananos


People also ask

How can you add marking objects on a Folium map?

Folium gives a folium. Marker() class for plotting markers on a map. Just pass the latitude and longitude of the location, mention the popup and tooltip and add it to the map.

Does Google Maps use Folium?

We used the geopy library to get the latitude and longitude of the location. Then we used the "folium. map" method of the folium package for creating the base of Google Maps. In step 2, we used "folium.


Video Answer


2 Answers

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

like image 144
Muhammad Haseeb Khan Avatar answered Oct 17 '22 13:10

Muhammad Haseeb Khan


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.

like image 3
Collin Reinking Avatar answered Oct 17 '22 14:10

Collin Reinking