Skip to content

Commit

Permalink
Make time optional in gpx
Browse files Browse the repository at this point in the history
  • Loading branch information
vanng822 committed Jun 7, 2016
1 parent 5075dc0 commit 96df164
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/gpx-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ var getTrk = function(trks) {
trkpts = trks[i].trkseg[0].trkpt;
for( j = 0, jlen = trkpts.length; j < jlen; j++) {
trkpt = trkpts[j];
if(trkpt.hasOwnProperty(ATTRIBUTE_NAME) && trkpt[ATTRIBUTE_NAME].hasOwnProperty('lat') && trkpt.hasOwnProperty('time')) {
if(trkpt.hasOwnProperty(ATTRIBUTE_NAME) && trkpt[ATTRIBUTE_NAME].hasOwnProperty('lat')) {
trk = new Trackpoint();
trk.lat = parseFloat(trkpt[ATTRIBUTE_NAME].lat);
trk.lng = parseFloat(trkpt[ATTRIBUTE_NAME].lon);
trk.time = new Date(trkpt.time);
if (trkpt.hasOwnProperty('time')) {
trk.time = new Date(trkpt.time);
}

if(trkpt.hasOwnProperty('ele')) {
trk.ele = parseFloat(trkpt.ele);
Expand Down
19 changes: 19 additions & 0 deletions tests/test_parse_gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ vows.describe('Test suite for parsing gpx').addBatch({
}]);
});
},
'Parse gpx data should return an array of two tracking points null time' : function() {
gpx.gpxParse(['<gpx version="1.1">', '<metadata>', '<link href="connect.garmin.com">', '<text>Garmin Connect</text>', '</link>', ' <time>2013-03-02T15:40:32.000Z</time>', ' </metadata>', '<trk>', '<name>Untitled</name>', ' <trkseg>', '<trkpt lon="17.661922238767147" lat="59.19305333867669">', '<ele>69.4000015258789</ele>', '</trkpt>', '<trkpt lon="17.662122901529074" lat="59.192982176318765">', '<ele>69.5999984741211</ele>', '</trkpt>', '</trkseg>', '</trk>', '</gpx>'].join(), function(err, result) {
assert.deepEqual(result, [{
distance : undefined,
speed : undefined,
lat : 59.19305333867669,
lng : 17.661922238767147,
ele : 69.4000015258789,
time : null
}, {
distance : undefined,
speed : undefined,
lat : 59.192982176318765,
lng : 17.662122901529074,
ele : 69.5999984741211,
time : null
}]);
});
},
'Parse gpx file data.gpx' : {
'topic' : function() {
gpx.gpxParseFile('./tests/data/data.gpx', this.callback);
Expand Down

0 comments on commit 96df164

Please sign in to comment.