Skip to content

Instantly share code, notes, and snippets.

@loopDelicious
Created June 21, 2016 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loopDelicious/26fa9b81e9074396032d94bd2b500cb0 to your computer and use it in GitHub Desktop.
Save loopDelicious/26fa9b81e9074396032d94bd2b500cb0 to your computer and use it in GitHub Desktop.
Mapbox API formatting
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