File size: 1,440 Bytes
c4b812c
 
 
 
 
 
 
 
 
 
aa166fc
 
 
 
 
 
 
 
 
 
c4b812c
 
 
 
 
 
aa166fc
 
 
 
 
 
 
 
c4b812c
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
import requests
import folium
from streamlit_folium import folium_static

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", {})
            # Assurez-vous que point_geo est un dictionnaire avec lat et lon.
            point_geo = fields.get("geolocalisation")
            if point_geo and isinstance(point_geo, list) and len(point_geo) == 2:
                # Stockez directement lat et lon dans fields pour un accès facile.
                fields["latitude"], fields["longitude"] = point_geo[0], point_geo[1]
                cleaned_data.append(fields)
        return cleaned_data
    else:
        return []

def display_map(data):
    m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
    for item in data:
        # Utilisez directement latitude et longitude.
        lat, lon = item.get("latitude"), item.get("longitude")
        if lat and lon:
            folium.Marker(
                [lat, lon],
                icon=folium.Icon(color="green", icon="leaf"),
                popup=item.get('nom_courant_denomination', 'Information non disponible'),
            ).add_to(m)
    folium_static(m)