shown location using map in python

To show a location using a map in Python, you can use the geopy library to retrieve the coordinates of a location through geocoding, and the folium library to plot the location on a map. Here's an example code:

main.py
import folium
from geopy.geocoders import Nominatim

# Get the coordinates of the location using geocoding
geolocator = Nominatim(user_agent="my_app")
location = geolocator.geocode("New York City")  # Replace with desired location
latitude, longitude = location.latitude, location.longitude

# Create a map centered at the location with a zoom level of 10
my_map = folium.Map(location=[latitude, longitude], zoom_start=10)

# Add a marker at the location
folium.Marker(location=[latitude, longitude], tooltip="Click for more info").add_to(my_map)

# Display the map
my_map
573 chars
17 lines

This code retrieves the coordinates of "New York City" using the Nominatim geocoder from geopy, creates a map centered at those coordinates using folium, adds a marker at the location on the map, and displays the map. You can replace "New York City" with any location you want to show on the map.

gistlibby LogSnag