Method: EncodedPolyline.decode_points

Defined in:
lib/encoded_polyline/core.rb

.decode_points(str, precision = 5) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/encoded_polyline/core.rb', line 44

def self.decode_points(str, precision=5)
  decoded_points = []
  point_chars = []

  str.each_char do |char|
    point_chars << char
    if ((char[0].ord - 63) & 0x20).zero?
      decoded_points << decode_arr(point_chars, precision)
      point_chars = []
    end
  end

  coordinates = [[decoded_points.shift, decoded_points.shift]]
   while decoded_points.any?
     coordinates << [
       coordinates.last[0] + decoded_points.shift,
       coordinates.last[1] + decoded_points.shift
     ]
   end
  return coordinates
end