Class: GoogleDistanceMatrix::PolylineEncoder
- Inherits:
-
Object
- Object
- GoogleDistanceMatrix::PolylineEncoder
- Defined in:
- lib/google_distance_matrix/polyline_encoder.rb,
lib/google_distance_matrix/polyline_encoder/delta.rb,
lib/google_distance_matrix/polyline_encoder/value_encoder.rb
Overview
Encodes a set of lat/lng pairs in to a polyline according to Google’s Encoded Polyline Algorithm Format.
See developers.google.com/maps/documentation/utilities/polylinealgorithm
Defined Under Namespace
Classes: Delta, ValueEncoder
Class Method Summary collapse
-
.encode(array_of_lat_lng_pairs) ⇒ Object
Encodes a set of lat/lng pairs.
Instance Method Summary collapse
-
#encode ⇒ Object
Encode and returns the encoded string.
-
#initialize(array_of_lat_lng_pairs, delta: Delta.new, value_encoder: ValueEncoder.new) ⇒ PolylineEncoder
constructor
Initialize a new encoder.
Constructor Details
#initialize(array_of_lat_lng_pairs, delta: Delta.new, value_encoder: ValueEncoder.new) ⇒ PolylineEncoder
Initialize a new encoder
Arguments
array_of_lat_lng_pairs - The array of lat/lng pairs, like [[lat, lng], [lat, lng], ..etc]
delta - An object responsible for rounding and calculate the deltas
between the given lat/lng pairs.
value_encoder - After deltas are calculated each value is passed to the encoder
to be encoded in to ASCII characters
30 31 32 33 34 35 |
# File 'lib/google_distance_matrix/polyline_encoder.rb', line 30 def initialize(array_of_lat_lng_pairs, delta: Delta.new, value_encoder: ValueEncoder.new) @array_of_lat_lng_pairs = array_of_lat_lng_pairs @delta = delta @value_encoder = value_encoder @encoded = nil end |
Class Method Details
.encode(array_of_lat_lng_pairs) ⇒ Object
16 17 18 |
# File 'lib/google_distance_matrix/polyline_encoder.rb', line 16 def self.encode(array_of_lat_lng_pairs) new(array_of_lat_lng_pairs).encode end |
Instance Method Details
#encode ⇒ Object
Encode and returns the encoded string
38 39 40 41 42 43 44 45 |
# File 'lib/google_distance_matrix/polyline_encoder.rb', line 38 def encode return @encoded if @encoded deltas = @delta.deltas_rounded @array_of_lat_lng_pairs chars_array = deltas.map { |v| @value_encoder.encode v } @encoded = chars_array.join end |