class GoogleDistanceMatrix::PolylineEncoder
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
Public Class Methods
encode(array_of_lat_lng_pairs)
click to toggle source
Encodes a set of lat/lng pairs
Example
encoded = PolylineEncoder.encode [[lat, lng], [lat, lng]]
# 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
new(array_of_lat_lng_pairs, delta: Delta.new, value_encoder: ValueEncoder.new)
click to toggle source
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
@see ::encode
# 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
Public Instance Methods
encode()
click to toggle source
Encode and returns the encoded string
# 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