Inam65 commited on
Commit
65d657f
·
verified ·
1 Parent(s): dd9b100

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -18
app.py CHANGED
@@ -36,32 +36,19 @@ with col3:
36
  # Search button
37
  if st.button("Search"):
38
  if location_search:
 
39
  try:
40
  location = geolocator.geocode(location_search, language="en")
41
  if location:
42
  st.session_state['latitude'] = location.latitude
43
  st.session_state['longitude'] = location.longitude
44
  st.session_state['location_name'] = location.address
45
- st.success(f"Location found: {location.address}")
46
  else:
47
- st.error("Location not found. Try another keyword.")
48
  except Exception as e:
49
- st.error(f"Error while searching the location: {e}")
50
- else:
51
- try:
52
- # If no search but lat/lon entered manually
53
- lat = float(latitude)
54
- lon = float(longitude)
55
- location = geolocator.reverse((lat, lon), language="en")
56
- if location:
57
- st.session_state['location_name'] = location.address
58
- st.success(f"Location updated to: {location.address}")
59
- else:
60
- st.warning("Coordinates valid, but no address found.")
61
- st.session_state['latitude'] = lat
62
- st.session_state['longitude'] = lon
63
- except ValueError:
64
- st.error("Invalid latitude or longitude input.")
65
 
66
  # Map
67
  st.subheader("Map View:")
 
36
  # Search button
37
  if st.button("Search"):
38
  if location_search:
39
+ with st.spinner("🔎 Searching for location..."):
40
  try:
41
  location = geolocator.geocode(location_search, language="en")
42
  if location:
43
  st.session_state['latitude'] = location.latitude
44
  st.session_state['longitude'] = location.longitude
45
  st.session_state['location_name'] = location.address
46
+ st.success(f"Location found: {location.address}")
47
  else:
48
+ st.error("Location not found. Try another keyword.")
49
  except Exception as e:
50
+ st.error(f"Error while searching the location: {e}")
51
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  # Map
54
  st.subheader("Map View:")