Python
geo
Published

April 27, 2023

Geocoding in Python

Get geographic coordinates for an address with Nominatim from OpenStreetMap data.

from geopy.geocoders import Nominatim

# Create a geolocator object
geolocator = Nominatim(user_agent="get-the-geocode")

# Define the address for geocoding
address = "Unter Sachsenhausen 6, Köln, Germany"

# Retrieve the geolocation (latitude and longitude) for the given address
location = geolocator.geocode(address)

print((location.latitude, location.longitude))
(50.9426743, 6.9523815)
import folium

coordinates = [location.latitude, location.longitude]

# Create a map object
m = folium.Map(location=coordinates, zoom_start=15)

# Add a marker for each coordinate
folium.Marker(location=coordinates, popup=address).add_to(m)

m  # Display the map in Jupyter Notebook
Make this Notebook Trusted to load map: File -> Trust Notebook