by mapbox

mapbox /polyline

polyline encoding and decoding in javascript

492 Stars 88 Forks Last release: over 1 year ago (1.1.0) BSD 3-Clause "New" or "Revised" License 93 Commits 7 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Build Status Coverage Status


A simple google-esque polyline implementation in Javascript. Compatible with nodejs (

npm install @mapbox/polyline
and the browser (copy

Encodes from / decodes into

[lat, lng]
coordinate pairs. Use
to encode from GeoJSON objects, or
to decode to a GeoJSON LineString.


npm install @mapbox/polyline

Note that the old package

has been deprecated in favor of
(the old package remain but won't receive updates).


var polyline = require('@mapbox/polyline');

// returns an array of lat, lon pairs polyline.decode('_piFps|U_ulLnnqC_mqNvxq`@');

// returns an array of lat, lon pairs from polyline6 by passing a precision parameter polyline.decode('cxl_cBqwvnS|[email protected]`IsnA|[email protected]@ljL', 6);

// returns a GeoJSON LineString feature polyline.toGeoJSON('_piFps|U_ulLnnqC_mqNvxq`@');

// returns a string-encoded polyline (from coordinate ordered lat,lng) polyline.encode([[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]);

// returns a string-encoded polyline from a GeoJSON LineString polyline.fromGeoJSON({ "type": "Feature", "geometry": { "type": "LineString", "coordinates": [[-120.2, 38.5], [-120.95, 40.7], [-126.453, 43.252]] }, "properties": {} });

API Documentation

Command line

Install globally or run


Send input via stdin and use

, or
flags. If omitted will default to

Example :

cat file.json | ./bin/polyline.bin.js --fromGeoJSON > result.txt

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.