File size: 1,372 Bytes
eb2ba11
dbd3890
 
74004b8
a72f593
eb2ba11
 
46f8b87
 
 
 
 
 
 
 
 
 
 
 
 
 
eb2ba11
1a5e86a
eb2ba11
 
 
46f8b87
 
 
 
 
 
1a5e86a
46f8b87
 
 
 
 
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
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"
    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", {})
            # Assumer que 'geolocalisation' contient directement les coordonnées [lat, lon]
            if 'geolocalisation' in fields:
                lat, lon = fields['geolocalisation']
                cleaned_data.append({"lat": lat, "lon": lon, "name": fields.get("nom_courant_denomination", "Inconnu")})
        return cleaned_data
    else:
        st.error("Failed to fetch data")
        return []

def display_map(data):
    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)

# Cette partie est pour exécuter le test directement dans ce fichier, si désiré
if __name__ == "__main__":
    data = get_data()
    display_map(data)