How to center my map around the middle of two geolocation points

Hello
I would like to know how to center my map around the middle of two geolocation points. For example I have two cities which would be the two extreme points of a diameter. And the map would be bounded by the perimeter of the circle. Is there a method, an option that allows me to center my map. Sorry in advance for my bad English.

from geopy.geocoders import Nominatim
import folium
import openrouteservice
from openrouteservice import convert

app = Nominatim(user_agent="tutorial")

# recupere dans dico la geolocation d'une ville via le module geopy

locationlat = app.geocode("Paris").raw
locationlong = app.geocode("Nice").raw

#first city
for key, value in locationlat.items():
    if key =='lat':
        lati1=value
    elif key =='lon':
        long1=value
 
# second city      
for key, value in locationlong.items():
    if key =='lat':
        lati2=value
    elif key =='lon':
        long2=value   
        
  
client = openrouteservice.Client(key='########')

coords = ((long1, lati1 ),(long2, lati2))
res = client.directions(coords)
geometry = client.directions(coords)['routes'][0]['geometry']
decoded = convert.decode_polyline(geometry)

distance_txt = "<h4> <b>Distance :&nbsp" + "<strong>"+str(round(res['routes'][0]['summary']['distance']/1000,1))+" Km </strong>" +"</h4></b>"
duration_txt = "<h4> <b>Temps du Trajet :&nbsp" + "<strong>"+str(round(res['routes'][0]['summary']['duration']/60,1))+" Mins. </strong>" +"</h4></b>"

#**center_map =  middle of circle**

m = folium.Map(location=[**center_map**],zoom_start=6, control_scale=True,tiles="cartodbpositron")
folium.GeoJson(decoded).add_child(folium.Popup(distance_txt+duration_txt,max_width=300)).add_to(m)

folium.Marker(
    location=list(coords[0][::-1]),
    popup="Départ",
    icon=folium.Icon(color="green"),
).add_to(m)

folium.Marker(
    location=list(coords[1][::-1]),
    popup="Paris",
    icon=folium.Icon(color="blue"),
).add_to(m)
m

Thank

Hey,

this is not a question related to the openrouteservice or its infrastructure.
Please refer to any general GIS, python or computer science forum, such as https://gis.stackexchange.com which will have answers such as this.

Best regards

1 Like

Thank You for reply
Best regards

2 Likes