Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
import googlemaps
|
|
|
4 |
import os
|
5 |
from datetime import datetime
|
6 |
|
@@ -16,40 +17,19 @@ def get_directions(source, destination):
|
|
16 |
directions_info[mode] = "No available routes."
|
17 |
return directions_info
|
18 |
|
19 |
-
def
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
}});
|
33 |
-
directionsRenderer.setMap(map);
|
34 |
-
var request = {{
|
35 |
-
origin: '{source}',
|
36 |
-
destination: '{destination}',
|
37 |
-
travelMode: 'DRIVING'
|
38 |
-
}};
|
39 |
-
directionsService.route(request, function(result, status) {{
|
40 |
-
if (status == 'OK') {{
|
41 |
-
directionsRenderer.setDirections(result);
|
42 |
-
}}
|
43 |
-
}});
|
44 |
-
}}
|
45 |
-
</script>
|
46 |
-
</head>
|
47 |
-
<body onload="initMap()">
|
48 |
-
<div id="map" style="height: 500px;"></div>
|
49 |
-
</body>
|
50 |
-
</html>
|
51 |
-
"""
|
52 |
-
components.html(html_code, height=600, scrolling=False)
|
53 |
|
54 |
# Initialize Google Maps
|
55 |
gmaps = googlemaps.Client(key=os.getenv('GOOGLE_KEY'))
|
@@ -73,4 +53,4 @@ if st.sidebar.button('Get Directions'):
|
|
73 |
|
74 |
show_map_button = st.button('Show Directions on Map πΊοΈ')
|
75 |
if show_map_button:
|
76 |
-
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit_folium import folium_static
|
3 |
import googlemaps
|
4 |
+
import folium
|
5 |
import os
|
6 |
from datetime import datetime
|
7 |
|
|
|
17 |
directions_info[mode] = "No available routes."
|
18 |
return directions_info
|
19 |
|
20 |
+
def render_folium_map(source, destination):
|
21 |
+
source_location = gmaps.geocode(source)
|
22 |
+
destination_location = gmaps.geocode(destination)
|
23 |
+
|
24 |
+
source_coords = source_location[0]['geometry']['location']
|
25 |
+
dest_coords = destination_location[0]['geometry']['location']
|
26 |
+
|
27 |
+
m = folium.Map(location=[source_coords['lat'], source_coords['lng']], zoom_start=10)
|
28 |
+
|
29 |
+
folium.Marker([source_coords['lat'], source_coords['lng']], tooltip='Source').add_to(m)
|
30 |
+
folium.Marker([dest_coords['lat'], dest_coords['lng']], tooltip='Destination').add_to(m)
|
31 |
+
|
32 |
+
folium_static(m)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Initialize Google Maps
|
35 |
gmaps = googlemaps.Client(key=os.getenv('GOOGLE_KEY'))
|
|
|
53 |
|
54 |
show_map_button = st.button('Show Directions on Map πΊοΈ')
|
55 |
if show_map_button:
|
56 |
+
render_folium_map(source_location, destination_location)
|