A simple google-esque polyline inspired
implementation in Javascript, extended to trajectory data structure (an additional time dimension added to the GPS coordinates). Compatible with nodejs (npm install trajectory.js
and the browser (copy src/trajectory.js
)).
Encodes from/decodes into [lat, lng, unix time in seconds]
tuples.
This library is heavily based on https://github.com/mapbox/polyline (In fact it is built on top of fork of it)
npm install trajectory.js
var trajectory = require('trajectory.js');
// returns an array of (lat, lon, unix time in seconds) tuples
trajectory.decode('_p~iF~ps|U_ynpijgz~G_ulLnnqC_c`|@_mqNvxq`@__t`B');
// returns an array of (lat, lon, unix time in seconds) tuples from trajectory6 by passing a precision parameter
trajectory.decode('_izlhA~rlgdF_c}mhpro}xA_{geC~ywl@_gjaR_kwzCn`{nI__qo]', 6);
// returns a string-encoded trajectory
trajectory.encode([[38.5, -120.2, 1582482601], [40.7, -120.95, 1582482611], [43.252, -126.453, 1582482627]]);
Takes a string representation of 1+ coordinate pairs and returns an array of (lat, lon, unix time in seconds) arrays. If not specified, precision defaults to 5.
Takes an array of (lat, lon, unix time in seconds) arrays and returns an encoded string. If not specified, precision defaults to 5.
Install globally or run ./node_modules/.bin/trajectory
.
Send input via stdin and use --decode
, --encode
flags. If omitted will default to --decode
.
Example :
$ echo '_p~iF~ps|U_ynpijgz~G_ulLnnqC_c`|@_mqNvxq`@__t`B' | ./bin/trajectory.bin.js
$ echo '[[38.5,-120.2,1582482601],[40.7,-120.95,1582482611],[43.252,-126.453,1582482627]]' | ./bin/trajectory.bin.js --encode
Issues and pull requests are welcome.
- For proposing new features/improvements or reporting bugs, create an issue.
- Check open issues for viewing existing ideas, verify if it is already proposed/being worked upon.
- When implementing new features make sure to add relavant tests and documentation before sending pull requests.