landmarks / app.py
Vishwas1's picture
Rename main.py to app.py
db5e560 verified
import streamlit as st
import folium
from streamlit_folium import folium_static
from map_handler import MapHandler
from wikipedia_handler import WikipediaHandler
from utils import get_current_location
def main():
st.set_page_config(page_title="Local Landmarks Map", layout="wide")
st.title("Discover Local Landmarks")
# Initialize handlers
map_handler = MapHandler()
wiki_handler = WikipediaHandler()
# Get user's current location (for initial map center)
lat, lon = get_current_location()
# Create a map centered on the user's location
m = map_handler.create_map(lat, lon)
# Create a container for the map
map_container = st.empty()
# Display the map
with map_container:
folium_static(m, width=1000, height=600)
# Get the current map bounds
bounds = map_handler.get_map_bounds(m)
# Fetch landmarks within the current map bounds
landmarks = wiki_handler.get_landmarks_in_area(bounds)
# Debug logging
st.write(f"Number of landmarks fetched: {len(landmarks)}")
# Add markers for each landmark
for landmark in landmarks:
map_handler.add_landmark_marker(m, landmark)
# Update the map display
with map_container:
folium_static(m, width=1000, height=600)
# Add a button to refresh landmarks
if st.button("Refresh Landmarks"):
# Get updated bounds
bounds = map_handler.get_map_bounds(m)
# Fetch new landmarks
landmarks = wiki_handler.get_landmarks_in_area(bounds)
# Debug logging
st.write(f"Number of landmarks fetched after refresh: {len(landmarks)}")
# Clear existing markers
map_handler.clear_markers(m)
# Add new markers
for landmark in landmarks:
map_handler.add_landmark_marker(m, landmark)
# Update the map display
with map_container:
folium_static(m, width=1000, height=600)
st.sidebar.header("About")
st.sidebar.info("This app displays local landmarks on an interactive map using data from Wikipedia. "
"Move around the map to discover new landmarks, and click on markers to learn more about them.")
if __name__ == "__main__":
main()