# Source: bemap-extensions/bemap-google-encoded-polyline.js

    bemap.gep = bemap.gep || {};

    bemap.gep.version = '1.0.0';

    /**
     * Decode the Google encoded polyline.
     * Originale source code form :
     * @see https://github.com/mapbox/polyline/blob/master/src/polyline.js
     * @see https://github.com/Project-OSRM/osrm-frontend/blob/master/WebContent/routing/OSRM.RoutingGeometry.js
     * @return List of BeMap JS coordinate.
     */
    bemap.gep.decode = function(str, precision) {
      if(!precision || precision < 0) {
        precision = 5;
      }

      var index = 0,
        lat = 0,
        lng = 0,
        coordinates = [],
        shift = 0,
        result = 0,
        byte = null,
        latitude_change,
        longitude_change,
        factor = Math.pow(10, Number.isInteger(precision) ? precision : 5);

      // Coordinates have variable length when encoded, so just keep
      // track of whether we've hit the end of the string. In each
      // loop iteration, a single coordinate is decoded.
      while (index < str.length) {
        // Reset shift, result, and byte
        byte = null;
        shift = 0;
        result = 0;

        do {
          byte = str.charCodeAt(index++) - 63;
          result |= (byte & 0x1f) << shift;
          shift += 5;
        } while (byte >= 0x20);

        latitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));

        shift = result = 0;

        do {
          byte = str.charCodeAt(index++) - 63;
          result |= (byte & 0x1f) << shift;
          shift += 5;
        } while (byte >= 0x20);

        longitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));

        lat += latitude_change;
        lng += longitude_change;

        //coordinates.push([lat / factor, lng / factor]);
        coordinates.push(new bemap.Coordinate(lng / factor, lat / factor));
      }

      return coordinates;
    };