-
-
Save kristofer84/0e9dea658cacf9cd0c46ec475211b0a9 to your computer and use it in GitHub Desktop.
Google export json to gpx
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
const fs = require('fs'); | |
const createGpx = require('gps-to-gpx').default; | |
const program = require('commander'); | |
program | |
.version('0.1.0') | |
.command('parse <inputFile>') | |
.option('--from <from>', 'From which date parse data YYYY-MM-DDTHH:ii.') | |
.option('--to <to>', 'To which date parse data YYYY-MM-DDTHH:ii.') | |
.option('--accuracy <accuracy>', 'Minimal accuracy.') | |
.action((inputFile, options) => { | |
const from = options.from ? new Date(options.from) : null; | |
const to = options.to ? new Date(options.to) : null; | |
const googleLocation = JSON.parse(fs.readFileSync(inputFile, 'utf8')); | |
let waypoints = googleLocation.locations; | |
if (from || to || options.accuracy) { | |
waypoints = waypoints.filter((item) => { | |
return (!from || (item.timestampMs >= from.getTime())) && | |
(!to || (item.timestampMs <= to.getTime())) && | |
(!options.accuracy || item.accuracy <= options.accuracy) | |
}); | |
} | |
waypoints = waypoints.map((item) => { | |
return { | |
time: new Date(Number(item.timestampMs)), | |
latitude: item.latitudeE7 / 10000000, | |
longitude: item.longitudeE7 / 10000000, | |
accuracy: item.accuracy, | |
elevation: item.altitude != null ? item.altitude : null, | |
}; | |
}); | |
fs.writeFileSync(inputFile.replace('.json', '.gpx'), createGpx(waypoints)); | |
}); | |
program.parse(process.argv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment