Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

polyline

mapbox41.1kdeprecated0.2.0TypeScript support: definitely-typed

This module is now under the @mapbox namespace: install @mapbox/polyline instead

Polyline encoding and decoding

readme

Build Status Coverage Status

polyline

A simple google-esque polyline implementation in Javascript. Compatible with nodejs (npm install polyline and the browser (copy src/polyline.js)).

Encodes/decodes into lat/lng coordinate pairs. Use fromGeoJSON() to encode from GeoJSON objects.

Installation

npm install polyline

Example

var polyline = require('polyline');

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

// returns a string-encoded polyline
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": {}
});

Documentation

See Also

changelog

0.2.0

  • Add .toGeoJSON method to convert an encoded polyline to GeoJSON LineString.

0.1.0

  • Add .fromGeoJSON method to encode GeoJSON geometries as polylines without needing to manually flip coordinates.