Refactor map rendering to use an empty container for better management and add latitude/longitude input fields
Browse files
app.py
CHANGED
@@ -53,14 +53,18 @@ def main():
|
|
53 |
st.error(f"Error fetching location data: {str(e)}")
|
54 |
else:
|
55 |
st.write("Select your location on the map:")
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
63 |
|
|
|
64 |
latitude = st.text_input("Latitude:", value=str(latitude) if 'latitude' in locals() else "")
|
65 |
longitude = st.text_input("Longitude:", value=str(longitude) if 'longitude' in locals() else "")
|
66 |
|
|
|
53 |
st.error(f"Error fetching location data: {str(e)}")
|
54 |
else:
|
55 |
st.write("Select your location on the map:")
|
56 |
+
# Use an empty container to manage the map rendering
|
57 |
+
map_placeholder = st.empty()
|
58 |
+
with map_placeholder:
|
59 |
+
default_location = [37.7749, -122.4194]
|
60 |
+
map_display = folium.Map(location=default_location, zoom_start=2)
|
61 |
+
folium.Marker(default_location, tooltip="Default Location").add_to(map_display)
|
62 |
+
map_data = st_folium(map_display, width=350, height=300)
|
63 |
+
if map_data and 'last_clicked' in map_data and map_data['last_clicked']:
|
64 |
+
latitude = map_data['last_clicked']['lat']
|
65 |
+
longitude = map_data['last_clicked']['lng']
|
66 |
|
67 |
+
# Latitude and Longitude input fields
|
68 |
latitude = st.text_input("Latitude:", value=str(latitude) if 'latitude' in locals() else "")
|
69 |
longitude = st.text_input("Longitude:", value=str(longitude) if 'longitude' in locals() else "")
|
70 |
|