Decoding and encoding of the google polyline algorithm as described at https://developers.google.com/maps/documentation/utilities/polylinealgorithm
(require '[com.michaelgaare.clojure-polyline :as polyline])
;; Decode a polyline string:
(polyline/decode "_p~iF~ps|U_ulLnnqC_mqNvxq`@")
;; => [[38.5 -120.2] [40.7 -120.95] [43.252 -126.453]]
;; Encode a collection of coordinates:
(polyline/encode [[38.5 -120.2] [40.7 -120.95] [43.252 -126.453]])
;; => "_p~iF~ps|U_ulLnnqC_mqNvxq`@"
encode
expects a collection of vectors of the format [latitude longitude]
, and returns the polyline encoded string.
decode
returns a vector of [latitude longitude]
vectors for a
given polyline encoded string.
You can add additional transforms to the encoder and decoder
transducer stacks, which are bound to encoder
and decoder
vars
respectively. For instance, to decode a polyline string as [longitude latitude]
pairs as some systems expect, you can do:
(into [] (comp polyline/decoder (map polyline/lonlat)) your-polystring)`
Release 0.4.1 on 2018-11-07
Release 0.4.0 on 2018-10-01
[[lat lon]] => String
, now decode is String => [[lat lon]]
.decode
codepath was completely rewritten as transducers,
about 4x performance improvement.:latitude
and :longitude
keysencoder
and decoder
vars respectivelycompact-coords
function - my least favorite
code remaining in the project - with a compress
transducerRelease 0.3.0 on 2018-09-24
encode
codepath completely rewritten to scrub out some of
the wacky stuff I did 6 years ago. As a result it's 19x faster.Copyright © 2018 Michael Gaare
Distributed under the Eclipse Public License, the same as Clojure.
Can you improve this documentation? These fine people already did:
Michael Gaare, mgaare & Alexander ScottEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close