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.
defp deps do
[{:polyline, "~> 1.3"}]
end
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}]