2

I am trying to write a piece of code that plots a list of markers on a map. The markers are formatted by longitude and latitude:

trip_markers[0:4]:

[[40.64499, -73.78115],
 [40.766931, -73.982098],
 [40.77773, -73.951902],
 [40.795678, -73.971049]]

I am trying to write a function that iterates through this list, and plots each point on a map.

def map_from(location, zoom_amount):
    return folium.Map(location=location, zoom_start=zoom_amount)

manhattan_map = map_from([40.7589, -73.9851], 13)

The code below seems to be the problem

def add_markers(markers, map_obj):
    for marker in markers:
        return marker and marker.add_to(map_obj)   

map_with_markers = add_markers(trip_markers, manhattan_map)

I expect my output of map_with_markers to produce a map with each point plotted

However I am getting:

<folium.vector_layers.CircleMarker at 0x7f453a365c50>
CarterB
  • 502
  • 1
  • 3
  • 13

2 Answers2

0

If you want to interate over the markers and add each one on a figure you could

def plot_mark( trip_markers):
    fig = plt.figure()
    for mark in trip_markers:
        plt.plot(mark[0], mark[1],'*') 
    return fig
Matteo Peluso
  • 452
  • 1
  • 6
  • 23
0

For anyone interested, I solved it. Simple solution. Just learning so trying to avoid obvious errors.

def add_markers(markers, map_obj):
        for marker in markers:
            marker.add_to(map_obj)
        return map_obj
CarterB
  • 502
  • 1
  • 3
  • 13