show multiple location in python

To show multiple locations on a map in Python, you can use the geopy library to geocode the addresses and get their latitude and longitude coordinates. Then, you can use the folium library to plot the locations on a map.

Here's an example code:

main.py
import geopy
import folium

# addresses of the locations
addresses = ['1600 Amphitheatre Parkway, Mountain View, CA',
             '1 Hacker Way, Menlo Park, CA',
             '345 Park Ave, San Jose, CA']

# geocode the addresses to get the latitude and longitude coordinates
geolocator = geopy.Nominatim(user_agent="my-application")

locations = []
for address in addresses:
    location = geolocator.geocode(address)
    locations.append({'Address': address,
                      'Latitude': location.latitude,
                      'Longitude': location.longitude})

# create a map and add markers for the locations
m = folium.Map(location=[37.7749,-122.4194], zoom_start=10)  # initialize the map with a center point

for loc in locations:
    popup = folium.Popup(loc['Address'])
    folium.Marker([loc['Latitude'], loc['Longitude']], popup=popup).add_to(m)

# display the map
m
886 chars
28 lines

This will create a map with markers for each location, as shown below:

Map with multiple locations

gistlibby LogSnag