Skip to content

Instantly share code, notes, and snippets.

@mneedham mneedham/
Last active Nov 18, 2018

What would you like to do?
Mapping Strava runs using Leaflet and Open Street Map
from flask import Flask
from flask import render_template
import csv
import json
app = Flask(__name__)
def my_runs():
runs = []
with open("runs.csv", "r") as runs_file:
reader = csv.DictReader(runs_file)
for row in reader:
return render_template("leaflet.html", runs = json.dumps(runs))
if __name__ == "__main__": = 5001)
import requests
import os
import sys
import csv
token = os.environ["TOKEN"]
headers = {'Authorization': "Bearer {0}".format(token)}
with open("runs.csv", "w") as runs_file:
writer = csv.writer(runs_file, delimiter=",")
writer.writerow(["id", "polyline"])
page = 1
while True:
r = requests.get("{0}".format(page), headers = headers)
response = r.json()
if len(response) == 0:
for activity in response:
r = requests.get("{0}?include_all_efforts=true".format(activity["id"]), headers = headers)
polyline = r.json()["map"]["polyline"]
writer.writerow([activity["id"], polyline])
page += 1
<title>Mapping my runs</title>
<script src=""></script>
<script type="text/javascript" src=""></script>
<link rel="stylesheet" href="" />
<div id="map" style="width: 100%; height: 100%"></div>
var map ='map').setView([51.498265, -0.135642], 13);
'http://{s}{z}/{x}/{y}.png', {
maxZoom: 18,
var encodedRoutes = {{ runs|safe }}
for (let encoded of encodedRoutes) {
var coordinates = L.Polyline.fromEncoded(encoded).getLatLngs();
color: 'blue',
weight: 2,
opacity: .7,
lineJoin: 'round'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.