def encode(points)
      last_lat = last_lng = 0
      result = ""

      points.each do |point|
        ll = GoogleMapsService::Convert.normalize_latlng(point)
        lat = (ll[0] * 1e5).round.to_i
        lng = (ll[1] * 1e5).round.to_i
        d_lat = lat - last_lat
        d_lng = lng - last_lng

        [d_lat, d_lng].each do |v|
          v = (v < 0) ? ~(v << 1) : (v << 1)
          while v >= 0x20
            result += ((0x20 | (v & 0x1f)) + 63).chr
            v >>= 5
          end
          result += (v + 63).chr
        end

        last_lat = lat
        last_lng = lng
      end

      result
    end
def encode(points)
      last_lat = last_lng = 0
      result = ""

      points.each do |point|
        ll = GoogleMapsService::Convert.normalize_latlng(point)
        lat = (ll[0] * 1e5).round.to_i
        lng = (ll[1] * 1e5).round.to_i
        d_lat = lat - last_lat
        d_lng = lng - last_lng

        [d_lat, d_lng].each do |v|
          v = (v < 0) ? ~(v << 1) : (v << 1)
          while v >= 0x20
            result += ((0x20 | (v & 0x1f)) + 63).chr
            v >>= 5
          end
          result += (v + 63).chr
        end

        last_lat = lat
        last_lng = lng
      end

      result
    end
Encodes a list of points into a polyline string.

 See the developer docs for a detailed description of this encoding:
 https://developers.google.com/maps/documentation/utilities/polylinealgorithm

 @param [Array<Hash>, Array<Array>] points A list of lat/lng pairs.

 @return [String]