decodePolyline static method

List<LatLng> decodePolyline(
  1. String encodedPath, {
  2. int precision = 5,
})

Decodes a polyline string back into path coordinates.

Implementation

static List<LatLng> decodePolyline(String encodedPath, {int precision = 5}) {
  if (encodedPath.isEmpty) {
    return const [];
  }

  final factor = math.pow(10, precision).toDouble();
  final points = <LatLng>[];
  var index = 0;
  var lat = 0;
  var lng = 0;

  while (index < encodedPath.length) {
    lat += _decodeValue(encodedPath, () => index++);
    lng += _decodeValue(encodedPath, () => index++);
    points.add(LatLng(lat / factor, lng / factor));
  }

  return points;
}