Created
October 13, 2018 17:37
-
-
Save jameshfisher/a0f664d8beb7db559ba74d527a907d8a to your computer and use it in GitHub Desktop.
Demonstration that Strava Route Builder can't find routes at the prime meridian
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
// Open https://www.strava.com/routes/new, then copy/paste this code in the debug console. | |
// It should print results like this, showing that it can't find routes at the prime meridian: | |
// | |
// lng: -1.0, errCount: 0 | |
// lng: -0.9, errCount: 0 | |
// lng: -0.8, errCount: 1 | |
// lng: -0.7, errCount: 0 | |
// lng: -0.6, errCount: 0 | |
// lng: -0.5, errCount: 0 | |
// lng: -0.4, errCount: 0 | |
// lng: -0.3, errCount: 0 | |
// lng: -0.2, errCount: 0 | |
// lng: -0.1, errCount: 0 | |
// lng: 0 , errCount: 17 <----- HERE'S YOUR PROBLEM | |
// lng: 0.1, errCount: 0 | |
// lng: 0.2, errCount: 0 | |
// lng: 0.3, errCount: 0 | |
// lng: 0.4, errCount: 0 | |
// lng: 0.5, errCount: 0 | |
// lng: 0.6, errCount: 0 | |
// lng: 0.7, errCount: 0 | |
// lng: 0.8, errCount: 0 | |
// lng: 0.9, errCount: 1 | |
// lng: 1.0, errCount: 0 | |
function routeBetweenPoints(a, b) { | |
return fetch('https://www.strava.com/routemaster/route', { | |
method: "POST", | |
headers: { | |
'Content-Type': 'application/json; charset=utf-8', | |
'X-CSRF-Token': document.getElementsByName('csrf-token')[0].getAttribute('content') | |
}, | |
body: JSON.stringify({ | |
elements: [ | |
{ element_type:1, waypoint: { point: a } }, | |
{ element_type:1, waypoint: { point: b } } | |
], | |
preferences: { | |
popularity: 1, | |
elevation: 0, | |
route_type: 1, | |
straight_line: false | |
} | |
}) | |
}).then(response => response.json()); | |
} | |
function routeAtLatLng(lat, lng) { | |
return routeBetweenPoints( | |
{ lat: lat, lng: lng-0.01 }, | |
{ lat: lat, lng: lng+0.01 } | |
); | |
} | |
function gen(from, to, by) { | |
const xs = []; | |
for (let x = from; x < to; x+=by) xs.push(x); | |
return xs; | |
} | |
function errsAtLng(lng) { | |
const lats = gen(44, 49, 0.2); | |
return Promise.all(lats.map(lat => routeAtLatLng(lat, lng))) | |
.then(routes => routes.filter(route => route.error === "Route request outside of routable paths")) | |
.then(errs => errs.length); | |
} | |
const lngs = gen(-1, 1, 0.1); | |
Promise.all(lngs.map(lng => | |
errsAtLng(lng) | |
.then(errCount => { return { lng: lng, errCount: errCount }; }) | |
)).then(results => console.log(results)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment