I'm trying to create a very simple leaflet/folium map using python.
It works without marker clusters (all the relevant locations show up on the map), but when I try using MarkerCluster I get the following error message 'module' object has no attribute 'MarkerCluster'
(in response to line 14, marker_cluster = folium.MarkerCluster().add_to(cyclemap)).
I'm not sure what I'm doing wrong, I've imported the package, I've definitely installed folium correctly.
My text editor also states 'folium.plugins.MarkerCluster imported but unused'
.
I'm completely new to python.
import folium
from folium.plugins import MarkerCluster
import pandas as pd
cyclemap = folium.Map(location = [51.5074, -0.1278],
tiles='CartoDB positron',
zoom_start = 11,
width = 800, height = 600)
cycleincidences = pd.read_csv("2016cyclists.csv")
MAX_RECORDS = 50
#using max records for speed as I have almost 5000 data points
marker_cluster = folium.MarkerCluster().add_to(cyclemap)
for each in cycleincidences[0:MAX_RECORDS].iterrows():
folium.Marker(
location = [each[1]['X'],each[1]['Y']]
).add_to(marker_cluster)
cyclemap.save('cylesmap3.html')
Best Answer
According to this notebook (https://github.com/python-visualization/folium/blob/master/examples/MarkerCluster.ipynb) you should try calling MarkerCluster directly. This is because you have imported that module already.