All Projects → googlemaps → js-polyline-codec

googlemaps / js-polyline-codec

Licence: Apache-2.0 license
Polyline encoding and decoding.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Google Maps JavaScript Polyline Encoding

npm Build Release codecov GitHub contributors semantic-release

Description

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 at https://developers.google.com/maps/documentation/utilities/polylinealgorithm.

Install

Available via npm as the package @googlemaps/polyline-codec.

npm i @googlemaps/polyline-codec

Documentation

The reference documentation can be found at this link.

Example

import { decode, encode } from "@googlemaps/polyline-codec";

const encoded = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
console.log(decode(encoded, 5));
// [
//   [38.5, -120.2],
//   [40.7, -120.95],
//   [43.252, -126.453],
// ]

const path = [
  [38.5, -120.2],
  [40.7, -120.95],
  [43.252, -126.453],
];
console.log(encode(path, 5));
// "_p~iF~ps|U_ulLnnqC_mqNvxq`@"
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].