Update app.py
Browse files
app.py
CHANGED
@@ -26,6 +26,25 @@ def render_folium_map(coords):
|
|
26 |
folium.PolyLine(coords, color="blue", weight=2.5, opacity=1).add_to(m)
|
27 |
return m
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# Streamlit UI
|
30 |
st.title('Google Maps and Minnesota Medical Centers')
|
31 |
st.sidebar.header('Directions')
|
@@ -49,6 +68,7 @@ if st.sidebar.button('Get Directions'):
|
|
49 |
st.markdown("## π₯ Minnesota Medical Centers π³")
|
50 |
m2 = folium.Map(location=[45.6945, -93.9002], zoom_start=6)
|
51 |
marker_cluster = MarkerCluster().add_to(m2)
|
|
|
52 |
# Define Minnesota medical centers data
|
53 |
minnesota_med_centers = [
|
54 |
('Mayo Clinic', 44.0224, -92.4658, 'General medical and surgical', 'Rochester'),
|
@@ -72,4 +92,7 @@ minnesota_med_centers = [
|
|
72 |
('Lakeview Hospital', 45.0422, -92.8137, 'Community hospital', 'Stillwater'),
|
73 |
('St. Luke\'s Hospital', 46.7831, -92.1043, 'Community hospital', 'Duluth')
|
74 |
]
|
|
|
|
|
|
|
75 |
folium_static(m2)
|
|
|
26 |
folium.PolyLine(coords, color="blue", weight=2.5, opacity=1).add_to(m)
|
27 |
return m
|
28 |
|
29 |
+
# Function to add medical center paths and annotate distance
|
30 |
+
def add_medical_center_paths(m, source, med_centers):
|
31 |
+
for name, lat, lon, specialty, city in med_centers:
|
32 |
+
_, coords = get_directions_and_coords(source, (lat, lon))
|
33 |
+
if coords:
|
34 |
+
folium.PolyLine(coords, color="red", weight=2.5, opacity=1).add_to(m)
|
35 |
+
folium.Marker([lat, lon], popup=name).add_to(m)
|
36 |
+
distance_info = gmaps.distance_matrix(source, (lat, lon), mode='driving')
|
37 |
+
distance = distance_info['rows'][0]['elements'][0]['distance']['text']
|
38 |
+
folium.PolyLine(coords, color='red').add_to(m)
|
39 |
+
folium.map.Marker(
|
40 |
+
[coords[-1][0], coords[-1][1]],
|
41 |
+
icon=folium.DivIcon(
|
42 |
+
icon_size=(150, 36),
|
43 |
+
icon_anchor=(0, 0),
|
44 |
+
html=f'<div style="font-size: 10pt; color : red;">{distance}</div>',
|
45 |
+
)
|
46 |
+
).add_to(m)
|
47 |
+
|
48 |
# Streamlit UI
|
49 |
st.title('Google Maps and Minnesota Medical Centers')
|
50 |
st.sidebar.header('Directions')
|
|
|
68 |
st.markdown("## π₯ Minnesota Medical Centers π³")
|
69 |
m2 = folium.Map(location=[45.6945, -93.9002], zoom_start=6)
|
70 |
marker_cluster = MarkerCluster().add_to(m2)
|
71 |
+
|
72 |
# Define Minnesota medical centers data
|
73 |
minnesota_med_centers = [
|
74 |
('Mayo Clinic', 44.0224, -92.4658, 'General medical and surgical', 'Rochester'),
|
|
|
92 |
('Lakeview Hospital', 45.0422, -92.8137, 'Community hospital', 'Stillwater'),
|
93 |
('St. Luke\'s Hospital', 46.7831, -92.1043, 'Community hospital', 'Duluth')
|
94 |
]
|
95 |
+
|
96 |
+
# Annotate distances and paths for each medical center
|
97 |
+
add_medical_center_paths(m2, source_location, minnesota_med_centers)
|
98 |
folium_static(m2)
|