St.map get current bounding box coordinates

Hi,
I want to create an application where the user gets an empty map, zooms to the desired area, clicks a button and then the data is downloaded from OSM. I am just missing the part on how to get the bounding box coordinates. The code should just give me the bounding box of the still empty map.

This is the code so far:

import streamlit as st
import requests

# Set layout
st.set_page_config(layout="wide", page_title="City_POIs")

# Main Content
st.title("Fetch the POIs in your city")

st.header("Choose a City")
st.write("Zoom to an area on the map below. The visible area of the map will be used to create the POIs.")

def fetch_pois(sw_lat, sw_lng, ne_lat, ne_lng):
    """Fetch POIs (restaurants) from OSM using the Overpass API."""
    overpass_url = "http://overpass-api.de/api/interpreter"
    overpass_query = f"""
    [out:json];
    (
    node["amenity"="restaurant"]({sw_lat},{sw_lng},{ne_lat},{ne_lng});
    node["amenity"="cafe"]({sw_lat},{sw_lng},{ne_lat},{ne_lng});
    );
    out body;
    """
    response = requests.get(overpass_url, params={'data': overpass_query})
    return response

map_figure = st.map()

if st.button("Fetch POIs"):
....

And then how? Thankful for any advice!

Versions
Python 3.10.12
Streamlit v1.36.0

st.map does not return anything. You could get the current bounding box using the streamlit-folium component. Check the docs at https://folium.streamlit.app/

2 Likes

I was just looking in the streamlit app, and see this https://folium.streamlit.app/ who answer the question. Come back, you already answer it :smiley: