polyline 1.0.0 copy "polyline: ^1.0.0" to clipboard
polyline: ^1.0.0 copied to clipboard

outdated

Polyline encoding algorithm

pub package

polyline.dart #

Polyline encoding is a lossy compression algorithm that allows you to store a series of coordinates as a single string.

Polyline is a dart port of Google's Polyline Algorithm explained here. Inspired by Mapbox's polyline.js. Compatible with Dart 2.

Installation #

Add polyline: any to your pubspec.yaml. Then run:

pub get

Usage #

A simple usage example:
Two named constructors are provided Polyline.Decode and Polyline.Encode.

Calling Polyline.Encode will compute the encodedString and set the passed in coordinates to decodedCoords on the instance of Polyline so that each instance of Polyline has access to the correct encoded string and subsequent decoded coordinates. Likewise, calling Polyline.Decode computes the list of coordinates from the encoded string and sets the passed in encoded string to the instance of Polyline.

Note that a precision of 5 is standard.

import 'package:polyline/polyline.dart';

void main() {
  Polyline polyline;
  const coordinates = [
    [33.80119, -84.34788],
    [35.10566, -80.8762],
    [30.4526, -81.71116],
    [28.57888, -81.2717]
  ];
  const precision = 5;
  const encoded = 'mxhmEfeyaO}w}F_aeTrxk[nabDv}lJsytA';

  // Encode a list of coordinates with precision 5 to produce the encoded string
  polyline = Polyline.Encode(
      decodedCoords: coordinates,
      precision: 5
  );
  print('Encoded String: ${polyline.encodedString}');
  print('Coords: ${polyline.decodedCoords}');

  // Decode an encoded string to a list of coordinates
  polyline = Polyline.Decode(
      encodedString: encoded,
      precision: precision
  );
  print('Decoded Coords: ${polyline.decodedCoords}');
  print('String: ${polyline.encodedString}');

}

See

Documentation #

Api Documentation

Features and bugs #

Please file feature requests and bugs at the issue tracker.