Search code examples
pythontwittergeolocationgeospatialfolium

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


How should I fix this? Basically, I want to create a map of tweets based on their geo information. All the tweets I have collected are within the USA and also have geo info.

Traceback (most recent call last):
  File "tweet_map.py", line 19, in <module>
    tweet_map.circle_marker(location=geo, radius=250)
AttributeError: 'Map' object has no attribute 'circle_marker'

Here's the code:

#create a map of tweets using Folium

import folium, pandas, ast

# get geo data only from rows with non-empty values
locations = pandas.read_csv('./usa_tweets.csv', usecols=[3]).dropna()

geos = []

for location in locations.values:
  # add to geos array an evaluated python literal syntax of the data
  geos.append(ast.literal_eval(location[0])['coordinates'])

# initialize and create map
tweet_map = folium.Map(location=[52.8, -2], tiles='Mapbox Bright', zoom_start=7)

# add markers
for geo in geos:
  tweet_map.circle_marker(location=geo, radius=250)

tweet_map.create

Solution

  • Thanks to the help from #Python IRC channel:

    for geo in geos:
      #tweet_map.CircleMarker(location=geo, radius=250)
      folium.CircleMarker(location=geo, radius=250).add_to(tweet_map)
    tweet_map.save('map.html')