google_polyline_algorithm 2.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

google_polyline_algorithm #

Build codecov Pub GitHub GitHub stars

Dart implementation of Googles Polyline Encoding lossy compression Algorithm.

Getting Started #

This package adds following methods to work with Googles Polyline Encoding Algorithm:

  • encodePoint(num current, {num previous = 0, int accuracyExponent = 5}) encodes a single coordinate

  • encodePolyline(List<List<num>> coordinates, {int accuracyExponent = 5}) encodes a list of coordinates into an encoded polyline stirng

  • decodePolyline(String polyline, {int accuracyExponent = 5}) decodes an encoded polyline string into a list of coordinates

Examples #

import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';

final coord = encodePoint(-179.9832104);
print(coord);
// output is `~oia@'

final coords = encodePolyline([
  [38.5, -120.2],
  [40.7, -120.95],
  [43.252, -126.453],
]);
print(coords);
// output is `_p~iF~ps|U_ulLnnqC_mqNvxq`@'

final polyline = decodePolyline('_p~iF~ps|U_ulLnnqC_mqNvxq`@');
print(polyline);
// output is [[38.5, -120.2],[40.7, -120.95],[43.252, -126.453],]

Changelog #

[2.0.0] #

  • Update dart version constraints

[1.0.0] #

  • Added encodePoint, encodePolyline and decodePolyline methods
  • Added Examples
  • Added Tests

example/google_polyline_algorithm_example.dart

// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';

void main() {
  final coord = encodePoint(-179.9832104);
  print(coord);
  // output is `~oia@'

  final coords = encodePolyline([
    [38.5, -120.2],
    [40.7, -120.95],
    [43.252, -126.453],
  ]);
  print(coords);
  // output is `_p~iF~ps|U_ulLnnqC_mqNvxq`@'

  final polyline = decodePolyline('_p~iF~ps|U_ulLnnqC_mqNvxq`@');
  print(polyline);
  // output is [[38.5, -120.2],[40.7, -120.95],[43.252, -126.453],]
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  google_polyline_algorithm: ^2.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
72
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0