File size: 1,500 Bytes
eb2ba11
dbd3890
 
74004b8
a72f593
eb2ba11
 
23ab2d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb2ba11
1a5e86a
7dd3dfa
23ab2d4
eb2ba11
23ab2d4
eb2ba11
46f8b87
 
 
 
 
 
23ab2d4
1a5e86a
46f8b87
 
7dd3dfa
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
import folium
from streamlit_folium import folium_static
import streamlit as st

def get_data():
    url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=100"
    try:
        response = requests.get(url)
        if response.status_code == 200:
            data = response.json()
            records = data.get("records", [])
            cleaned_data = []
            for record in records:
                fields = record.get("fields", {})
                geoloc = fields.get("geolocalisation")
                if geoloc:
                    lat, lon = geoloc[0], geoloc[1]
                    cleaned_data.append({"lat": lat, "lon": lon, "name": fields.get("nom_courant_denomination", "Inconnu")})
            return cleaned_data
        else:
            st.error(f"Failed to fetch data. Status code: {response.status_code}")
            return []
    except requests.exceptions.RequestException as e:
        st.error(f"Error occurred: {e}")
        return []

def display_map(data):
    # Initialiser la carte au centre de Bordeaux
    m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
    
    for item in data:
        lat, lon = item["lat"], item["lon"]
        folium.Marker(
            [lat, lon],
            popup=item["name"],
            icon=folium.Icon(color="green", icon="leaf"),
        ).add_to(m)
    
    folium_static(m)

if __name__ == "__main__":
    data = get_data()
    display_map(data)