'''
@app.route('/directions', methoden = ['GET', 'POST'])
def get_terminal_directions():
Code: Select all
if request.method == 'POST':
form_data = request.json
terminal = form_data['terminal']
session['terminal'] = terminal
terminal = session.get('terminal')
print('Session' + session.get('terminal'))
_, location_data = get_location()
#latitude = data['location']['lat']
#longitude = data['location']['lng']
latitude = 41.97750594826151
longitude = -87.9055705049776
# destination = quote(f"Terminal:, O'Hare International Airport")
destination = "Terminal:" + terminal + "O'Hare International Airport"
DIRECTIONS_URL = f'https://maps.googleapis.com/maps/api/directions/json?destination={destination}&origin={latitude},{longitude}&mode=walking&key=AIzaSyDaTHaEQ1jwYb-FZSwk-NVJgP9c0PzjS7E'
try:
headers = {
'Content-Type': 'application/json'
}
response = requests.get(
DIRECTIONS_URL,
headers=headers,
)
if response.status_code == 200:
data = response.json()
print('after' + terminal)
return data
else:
error_message = response.json().get('error', {}).get('message', 'Unknown error')
return jsonify({
"error": f"Google Directions API error: {error_message}"
}), response.status_code
except Exception as e:
return jsonify({
"error": str(e)
}), 500