-
Notifications
You must be signed in to change notification settings - Fork 0
/
WashroomFinder.py
43 lines (34 loc) · 1.47 KB
/
WashroomFinder.py
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
37
38
39
40
41
42
43
import streamlit as st
import pandas as pd
import geocoder
import geopy.distance
def get_current_location():
# Get location using IP
g = geocoder.ip('me')
return g.latlng
def fetch_closest_washroom(lat, lon, df):
closest_washroom = None
min_distance = float('inf') # Initialize with a very large number
for _, row in df.iterrows():
dist = geopy.distance.distance((lat, lon), (row['Latitude'], row['Longitude'])).km
if dist < min_distance:
min_distance = dist
closest_washroom = row
return closest_washroom
def main():
# Correcting column names and loading washrooms data
df_washrooms = pd.read_csv('Bathrooms.csv')
df_washrooms.columns = df_washrooms.columns.str.strip() # Removing any trailing spaces in column names
st.title('Welcome to the Hackathon Project')
st.header('Public Washroom Finder')
if st.button("Use Current Location", key="app_washroom_finder_button"):
latlng = get_current_location()
if latlng:
closest_washroom = fetch_closest_washroom(latlng[0], latlng[1], df_washrooms)
if closest_washroom is not None:
st.write(f"Closest Washroom: {closest_washroom['Title']}")
st.markdown(f"[View on Google Maps]({closest_washroom['URL']})")
else:
st.error("No washrooms found near your current location.")
else:
st.error("Could not determine your current location.")