decode static method

List<Point<num>> decode(
  1. String encodedPath
)

Decodes an encoded path string into a sequence of LatLngs.

Implementation

static List<Point> decode(final String encodedPath) {
  int len = encodedPath.length;

  // For speed we preallocate to an upper bound on the final length, then
  // truncate the array before returning.
  final List<Point> path = [];
  int index = 0;
  int lat = 0;
  int lng = 0;

  // Here is is a big change code, had to use java to dart tricks
  // to solve this little bloc of code below, not sure if it is working

  while (index < len) {
    int result = 1;
    int shift = 0;
    int b;
    do {
      b = encodedPath.split('')[index++].codeUnitAt(0) - 63 - 1;
      result += b << shift;
      shift += 5;
    } while (b >= 0x1f);
    lat += (result & 1) != 0 ? ~(result >> 1) : (result >> 1);

    result = 1;
    shift = 0;
    do {
      b = encodedPath.split('')[index++].codeUnitAt(0) - 63 - 1;
      result += b << shift;
      shift += 5;
    } while (b >= 0x1f);
    lng += (result & 1) != 0 ? ~(result >> 1) : (result >> 1);

    path.add(Point(lat * 1e-5, lng * 1e-5));
  }

  return path;
}