Class: GoogleDistanceMatrix::PolylineEncoder::Delta

Inherits:
Object
  • Object
show all
Defined in:
lib/google_distance_matrix/polyline_encoder/delta.rb

Overview

Calculates deltas between lat_lng values, internal helper class for PolylineEncoder.

According to the Google’s polyline encoding spec:

"Additionally, to conserve space, points only include the offset
from the previous point (except of course for the first point)"

Instance Method Summary collapse

Constructor Details

#initialize(precision = 1e5) ⇒ Delta

Returns a new instance of Delta.



13
14
15
# File 'lib/google_distance_matrix/polyline_encoder/delta.rb', line 13

def initialize(precision = 1e5)
  @precision = precision
end

Instance Method Details

#deltas_rounded(array_of_lat_lng_pairs) ⇒ Object

Takes a set of lat/lng pairs and calculates delta

Returns a flatten array where each lat/lng delta pair is put in order.



20
21
22
23
# File 'lib/google_distance_matrix/polyline_encoder/delta.rb', line 20

def deltas_rounded(array_of_lat_lng_pairs)
  rounded = round_to_precision array_of_lat_lng_pairs
  calculate_deltas rounded
end