Anne314159 commited on
Commit
048a55f
·
verified ·
1 Parent(s): 53cdd83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py CHANGED
@@ -193,8 +193,68 @@ def get_route(start_coord, end_coord):
193
  st.error(f"Failed to get route data. Status code: {response.status_code}, Response: {response_text}")
194
  return None
195
 
 
 
 
 
 
 
 
 
 
 
 
196
 
 
 
197
  def page_vacation():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  st.title("Route Finder with OpenRouteService")
199
 
200
  # Inputs for start and end coordinates
 
193
  st.error(f"Failed to get route data. Status code: {response.status_code}, Response: {response_text}")
194
  return None
195
 
196
+
197
+ from geopy.geocoders import Nominatim
198
+
199
+ def geocode_location(location_name):
200
+ geolocator = Nominatim(user_agent="streamlit_route_finder")
201
+ location = geolocator.geocode(location_name)
202
+ if location:
203
+ return (location.longitude, location.latitude)
204
+ else:
205
+ st.error(f"Could not geocode location name: {location_name}")
206
+ return None
207
 
208
+
209
+ # The updated page_vacation function using location names
210
  def page_vacation():
211
+ st.title("Route Finder with Named Locations")
212
+
213
+ # Inputs for start and end locations by name
214
+ st.header("Start Point")
215
+ start_location_name = st.text_input("Enter Start Location Name", "Brandenburg Gate, Berlin")
216
+
217
+ st.header("End Point")
218
+ end_location_name = st.text_input("Enter End Location Name", "Reichstag Building, Berlin")
219
+
220
+ if st.button("Find Route"):
221
+ # Geocode the location names to get the coordinates
222
+ start_coords = geocode_location(start_location_name)
223
+ end_coords = geocode_location(end_location_name)
224
+
225
+ if start_coords and end_coords:
226
+ # Fetch the route using the geocoded coordinates
227
+ route = get_route(start_coords, end_coords)
228
+ if route:
229
+ # Convert the route to a DataFrame
230
+ route_df = pd.DataFrame(route, columns=['lon', 'lat'])
231
+
232
+ # Create the route data for PyDeck
233
+ route_data = [{'path': route}]
234
+
235
+ # Display the route using PyDeck
236
+ st.pydeck_chart(pdk.Deck(
237
+ map_style='mapbox://styles/mapbox/light-v9',
238
+ initial_view_state=pdk.ViewState(
239
+ latitude=start_coords[1],
240
+ longitude=start_coords[0],
241
+ zoom=11,
242
+ pitch=50,
243
+ ),
244
+ layers=[
245
+ pdk.Layer(
246
+ 'PathLayer',
247
+ data=route_data,
248
+ get_path='path',
249
+ width_scale=20,
250
+ width_min_pixels=2,
251
+ get_color=[255, 140, 0], # Orange color
252
+ pickable=True
253
+ ),
254
+ ],
255
+ ))
256
+
257
+ def page_vacation_old():
258
  st.title("Route Finder with OpenRouteService")
259
 
260
  # Inputs for start and end coordinates