show multiple location in map in python

One way to show multiple locations on a map in Python is by using the folium library. Here's an example code snippet:

main.py
import folium

# create a map object centered at [latitude, longitude]
center = [40.7128, -74.0060]
m = folium.Map(location=center, zoom_start=13)

# add markers for each location
locations = [[40.7128, -74.0060], [37.7749, -122.4194], [51.5074, -0.1278]]

for loc in locations:
    folium.Marker(location=loc).add_to(m)

# save the map as an HTML file
m.save('map.html')
372 chars
15 lines

In this example, we first create a map object centered at a specific latitude and longitude using the folium.Map() function. Next, we create a list of the locations we want to mark on the map, and use a for loop to add a marker for each location using the folium.Marker() function.

Finally, we save the map as an HTML file using the save() method. When we open the HTML file, we should see a map with markers at each of the specified locations.

gistlibby LogSnag