Module: GoogleMapsPolyline

Defined in:
lib/googlemaps_polyline/core.rb,
lib/googlemaps_polyline/decoder.rb,
lib/googlemaps_polyline/encoder.rb,
lib/googlemaps_polyline/version.rb

Defined Under Namespace

Classes: Decoder, Encoder

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.decode_points_and_levels(points, levels) ⇒ Object



24
25
26
27
28
# File 'lib/googlemaps_polyline/core.rb', line 24

def self.decode_points_and_levels(points, levels)
  decoded_points = Decoder.new(StringIO.new(points)).decode_points
  decoded_levels = Decoder.new(StringIO.new(levels)).decode_levels
  return decoded_points, decoded_levels
end

.decode_polyline(points, levels) ⇒ Object



35
36
37
38
# File 'lib/googlemaps_polyline/core.rb', line 35

def self.decode_polyline(points, levels)
  records = self.decode_polyline_1e5(points, levels)
  return records.map { |lat, lng, level| [lat.to_f / 1e5, lng.to_f / 1e5, level] }
end

.decode_polyline_1e5(points, levels) ⇒ Object



30
31
32
33
# File 'lib/googlemaps_polyline/core.rb', line 30

def self.decode_polyline_1e5(points, levels)
  decoded_points, decoded_levels = self.decode_points_and_levels(points, levels)
  return decoded_points.zip(decoded_levels).map { |a| a.flatten }
end

.encode_points_and_levels(points, levels) ⇒ Object



7
8
9
10
11
# File 'lib/googlemaps_polyline/core.rb', line 7

def self.encode_points_and_levels(points, levels)
  encoded_points = Encoder.new(StringIO.new).encode_points(points).string
  encoded_levels = Encoder.new(StringIO.new).encode_levels(levels).string
  return encoded_points, encoded_levels
end

.encode_polyline(records) ⇒ Object



19
20
21
22
# File 'lib/googlemaps_polyline/core.rb', line 19

def self.encode_polyline(records)
  records_1e5 = records.map { |lat, lng, level| [(lat * 1e5).to_i, (lng * 1e5).to_i, level] }
  return self.encode_polyline_1e5(records_1e5)
end

.encode_polyline_1e5(records) ⇒ Object



13
14
15
16
17
# File 'lib/googlemaps_polyline/core.rb', line 13

def self.encode_polyline_1e5(records)
  points = records.map { |record| record[0..1] }
  levels = records.map { |record| record[2] }
  return self.encode_points_and_levels(points, levels)
end