Encode and decode polyines in Nodejs or the browser using this package.
Polyline encoding is a lossy compression algorithm that allows you to store a series of coordinates as a single string. Point coordinates are encoded using signed values.
Read more athttps://developers.google /maps/documentation/utilities/polylinealgorithm.
Available via npm as the package@googlemaps/polyline-codec.
npm i @googlemaps/polyline-codec
The reference documentation can be found at thislink.
import{decode,encode}from"@googlemaps/polyline-codec";
constencoded="_p~iF~ps|U_ulLnnqC_mqNvxq`@";
console.log(decode(encoded,5));
// [
// [38.5, -120.2],
// [40.7, -120.95],
// [43.252, -126.453],
// ]
constpath=[
[38.5,-120.2],
[40.7,-120.95],
[43.252,-126.453],
];
console.log(encode(path,5));
// "_p~iF~ps|U_ulLnnqC_mqNvxq`@"