show the way using actual routes map in python

To show the way using actual routes map in Python, you can use several libraries such as folium, geopy, and gmaps. Here's an example using folium:

main.py
import folium
from geopy.geocoders import Nominatim
from folium.plugins import PolyLineTextPath

# Initialize the map
m = folium.Map(location=[51.507351, -0.127758], zoom_start=13)

# Define the start and end points
geolocator = Nominatim(user_agent="show_the_way")
start_location = geolocator.geocode("London Eye, London")
end_location = geolocator.geocode("Buckingham Palace, London")

# Get the latitude and longitude of the points
start_latitude, start_longitude = start_location.latitude, start_location.longitude
end_latitude, end_longitude = end_location.latitude, end_location.longitude

# Create a list of coordinates
coordinates = [(start_latitude,start_longitude), (end_latitude,end_longitude)]

# Add the route line to the map
folium.PolyLine(locations=coordinates, weight=5, color='red').add_to(m)

# Add the start and end markers to the map
folium.Marker(location=[start_latitude, start_longitude], icon=folium.Icon(color='green')).add_to(m)
folium.Marker(location=[end_latitude, end_longitude], icon=folium.Icon(color='red')).add_to(m)

# Add the route text label to the map
PolyLineTextPath(polyline=coordinates, text='Route', offset=-5).add_to(m)

# Show the map
m
1182 chars
32 lines

In this example, we use the folium library to create a map with the specified zoom level and center it on London. We then use the geopy library to geocode the start and end points and get their latitude and longitude coordinates. We then create a list of coordinates with the start and end points and add a PolyLine to the map with the coordinates. Finally, we add start and end markers to the map, as well as a text label for the route using the PolyLineTextPath plugin.

gistlibby LogSnag