0

While discovering Folium got an AttributeError while trying to add a Marker to a folium map.

import folium

map_osm=folium.Map(location=[50.4547,30.5238], zoom_start=6, tiles='Stamen Terrain')
map_osm.Marker(location=[45.463612, 29.294559], popup='Solar Power Station')

map_osm.save('spst.html')

However, I get the following error:

AttributeError: 'Map' object has no attribute 'Marker'

Appreciate any help on how to get around this!

mrvlad
  • 7
  • 1
  • 2
  • 1
    In your case I would go for map_osm.add_children(folium.Marker(location=[45.463612, 29.294559], popup='Solar Power Station')), instead. But this may depend on the Folium version you are using. – tagoma May 18 '17 at 20:02

2 Answers2

1

The correct syntax is the following:

folium.Marker([45.463612, 29.294559], popup='Solar Power Station').add_to(map_osm)

So your code should look like

import folium

map_osm=folium.Map(location=[50.4547,30.5238], zoom_start=6, tiles='Stamen Terrain')
folium.Marker([45.463612, 29.294559], popup='Solar Power Station').add_to(map_osm)

map_osm.save('spst.html')
0

You probably have an old version of Folium. Try:

pip install -U folium