Skip to content

pkinney/polyline_ex

Repository files navigation

Polyline Encode/Decode for Elixir

Build Status Hex.pm

This is an Elixir implementation of polyline encoding/decoding. Functions are provided to convert a List of {lon, lat} tuples to a String polyline representation and back.

Note: while a lot of libraries use [latitude, longitude] ordering, this library maintains proper cartesian order ({x, y} or {longitude, latitude}) in order to be more interoperable with common formats such as GeoJSON and WKT.

Installation

defp deps do
  [{:polyline, "~> 1.3"}]
end

Usage

Full Documentation

The encode functions accept a precision parameter that defines the number of significant digits to retain when encoding. The same precision must be supplied to the decode or the resulting linestring will be incorrect. The default is 5, which correlates to approximately 1 meter of precision.

Polyline.encode([{-120.2, 38.5}, {-120.95, 40.7}, {-126.453, 43.252}]) #+> "_p~iF~ps|U_ulLnnqC_mqNvxq`@"

Polyline.decode("_p~iF~ps|U_ulLnnqC_mqNvxq`@") #=> [{-120.2, 38.5}, {-120.95, 40.7}, {-126.453, 43.252}]

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages