I have a GPX from my Strava ZIP that looks like this (I've snipped away most of the track points), where the first <trkpt> has no lon or lat attributes:
ui.js:105 TypeError: Cannot read property 'lat' of undefined
at track.js:28
at Array.map (<anonymous>)
at track.js:27
at Array.forEach (<anonymous>)
at track.js:26
at Array.forEach (<anonymous>)
at track.js:23
at track.js:137
at f.<anonymous> (parser.js:303)
at f.a.emit (events.js:146)
at o.onclosetag (parser.js:261)
at P (sax.js:624)
at L (sax.js:629)
at B (sax.js:889)
at o.write (sax.js:1436)
at f.parseString (parser.js:322)
at f.parseString (parser.js:5)
at track.js:133
at new Promise (<anonymous>)
at track.js:132
(anonymous) @ ui.js:105
w @ runtime.js:65
(anonymous) @ runtime.js:303
t.<computed> @ runtime.js:117
S @ image.js:62
a @ image.js:62
Promise.then (async)
S @ image.js:62
s @ image.js:62
(anonymous) @ image.js:62
(anonymous) @ image.js:62
(anonymous) @ ui.js:97
C @ ui.js:110
(anonymous) @ ui.js:356
It happens because the first track point doesn't have latitude or longitude attributes (see GPX above).
This fix is use reduce instead of map, and discard track points unless they have attributes. (A chained filter and map could be used, but this should have better performance for thousands of points.)
About the data: the problematic file was generated by combining two files using this tool, which is recommended by Strava so will be quite widely used. I don't have the original pre-merge files handy to check if the same issue occurs there or if it was introduced by the merge tool.
I've tested the fix locally with my full Strava archive (1,330 files) and they all load.
Thanks for this great site!
I have a GPX from my Strava ZIP that looks like this (I've snipped away most of the track points), where the first
<trkpt>
has nolon
orlat
attributes:It fails to load at https://erik.github.io/derive/ and logs this in the console:
The error is here: https://github.com/erik/derive/blob/88b9255c795cb7802969e35a1c96aa717d02afcf/src/track.js#L26-L33
It happens because the first track point doesn't have latitude or longitude attributes (see GPX above).
This fix is use
reduce
instead ofmap
, and discard track points unless they have attributes. (A chainedfilter
andmap
could be used, but this should have better performance for thousands of points.)About the data: the problematic file was generated by combining two files using this tool, which is recommended by Strava so will be quite widely used. I don't have the original pre-merge files handy to check if the same issue occurs there or if it was introduced by the merge tool.
I've tested the fix locally with my full Strava archive (1,330 files) and they all load.