Created
June 21, 2016 07:10
-
-
Save loopDelicious/26fa9b81e9074396032d94bd2b500cb0 to your computer and use it in GitHub Desktop.
Mapbox API formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
accessToken = os.environ["MAPBOX_API_KEY"] | |
@app.route('/route_directions') | |
def get_directions_geojson(): | |
"""Get directions via Mapbox Directions API with all the waypoints in the session.""" | |
waypoints = session['waypoints'] | |
route_list = [] | |
for waypoint in waypoints: | |
lng = str(waypoint['coordinates'][0]) | |
lat = str(waypoint['coordinates'][1]) | |
pair = lng + ',' + lat | |
route_list.append(pair) | |
route_list = ';'.join(route_list) | |
url = "https://api.mapbox.com/directions/v5/mapbox/walking/%s.json?access_token=%s&geometries=geojson&steps=true" % (route_list, accessToken) | |
response = requests.get(url) | |
response = response.json() | |
return jsonify(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment