Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Geopy/Geopy_Display_markers_on_map.ipynb
2973 views
Kernel: Python 3

Geopy.png

Geopy - Display markers on map from addresses

Give Feedback | Bug report

Tags: #geopy #folium #operations #navigation

Last update: 2023-07-28 (Created: 2023-07-28)

Description: This notebook demonstrates how to display markers on a map from addresses using geopy and folium.

Input

Import libraries

from geopy.geocoders import Nominatim try: import folium except ModuleError: !pip install folium --user import folium

Setup variables

Mandatory

  • address1: Address to be used to get coordinates

  • address2: Address to be used to get coordinates

Optional

  • zoom_start: This parameter sets the initial zoom level on the map. A value of 0 indicates the lowest level of zoom.

# Mandatory address1 = "Bulgaria Blvd 69, 1404 Manastirski Livadi, Sofia, Bulgaria" address2 = "1600 Amphitheatre Parkway Mountain View, CA 94043, USA" # Optional zoom_start = 2

Model

Get locations

geolocator = Nominatim(user_agent="geoapiExercises") location1 = geolocator.geocode(address1) location2 = geolocator.geocode(address2)

Create map

# Create a map centered around the two locations avg_latitude = (location1.latitude + location2.latitude) / 2 avg_longitude = (location1.longitude + location2.longitude) / 2 folium_map = folium.Map(location=[avg_latitude, avg_longitude], zoom_start=zoom_start) # Add markers for the specified locations folium.Marker([location1.latitude, location1.longitude], popup=folium.Popup(location1.address)).add_to(folium_map) folium.Marker([location2.latitude, location2.longitude], popup=folium.Popup(location2.address)).add_to(folium_map)

Output

Display map

folium_map