google_maps_utils 1.2.0+3

An Android Google Maps Utils original java project port for Flutter #

A Flutter/Dart project based on Android Google Maps Utils converted/ported to Dart/Flutter There are many packages that features Google Maps Utils, but none has the 3 main classes from the sources

Status: 3 of 78 classes converted #

How it works #

This is a project for converting all of the tools from Android Google Maps Utils partially. Initial commits from the 3 main Classes, MathUtils.java, PolyUtils.java and SphericalUtils.java

The same rules for calculating bounds, distance between two Point points and other polyline features are the same as used on Android native Java/Kotlin logic.

All of the methods of current classes available are ported

You can request classes for me to port as an issue, the classes ported are what most people uses

Main project: https://github.com/googlemaps/android-maps-utils

Main project questions: https://stackoverflow.com/questions/tagged/android-maps-utils

Fluttert community request: https://github.com/flutter/flutter/issues/24689

Example *.dart #

import 'package:google_maps_utils/google_maps_utils.dart';

void main() {
    Point from = Point(0.0, 0.0);
    Point to = Point(10.0, 5.0);
    Point randomPoint = Point(-23.54545, -23.898098);

    double distance = SphericalUtils.computeDistanceBetween(from, to);
    print('Distance: $distance meters');

    double heading = SphericalUtils.computeHeading(from, to);
    print('Heading: $heading degrees');

    double angle = SphericalUtils.computeAngleBetween(from, to);
    print('Angle: $angle degrees');

    double distanceToAB = PolyUtils.distanceToLine(randomPoint, from, to);
    print('Distance to Line: $distanceToAB meters');

    /// Distance: 1241932.6430813475
    /// Heading: 26.302486345342523
    /// Angle: 0.19493500057547358
    /// Distance to Line: 3675538.1518512294

    /// See grid path on: https://developers.google.com/maps/documentation/utilities/polylinealgorithm

    List<Point> path = PolyUtils.decode(
        'wjiaFz`hgQs}GmmBok@}vX|cOzKvvT`uNutJz|UgqAglAjr@ijBz]opA|Vor@}ViqEokCaiGu|@byAkjAvrMgjDj_A??ey@abD');

    print('path size length: ${path.length}');

    List<Point> simplifiedPath = PolyUtils.simplify(path, 5000);
    String simplifiedPathEncoded = PolyUtils.encode(simplifiedPath);

    print('simplified path: $simplifiedPathEncoded');
    print('path size simplified length: ${simplifiedPath.length}');
    /// Example by: https://github.com/nicolascav
    Point point = Point(-31.623060136389135, -60.68669021129609);

    /// Triangle
    List<Point> polygon = [
        Point(-31.624115, -60.688734),
        Point(-31.624115, -60.684657),
        Point(-31.621594, -60.686717),
        Point(-31.624115, -60.688734),
    ];

    bool contains = PolyUtils.containsLocationPoly(point, polygon);
    print('point is inside polygon?: $contains');

    /// And Many more
}

Result: #

Distance: 1241932.6430813475 meters #
Heading: 26.302486345342523 degrees #
Angle: 0.19493500057547358 degrees #
Distance to Line: 3675538.1518512294 meters #
path size length: 17 #
simplified path: wjiaFz`hgQcjIke\t{d@|aOutJz|UokC}xWomJdjM #
path size simplified length: 6 #
point is inside polygon?: true #

1.0.0+1: #

Added SphericalUtils and MathUtils

1.0.0+2: #

Added Readme, License and PolyUtils

1.0.0+3: #

Simplified and shorted some codes Fixed Readme

1.1.0+1: #

Added Changelog and formated all files, updated stack package from ^0.0.1 to ^0.1.0 Removed google maps package, replaced for created Lightweight Point and LatLngBounds classes (lat_lng.dart) Fixed docs in all classes Added example.dart

1.1.0+2 #

Fixed description

1.1.0+3 #

Fixed description

1.1.1+0 #

Fixed poly_utils.dart, all 3 functions are working as expected Removed unnecessary dependencies Updated example.dart Added example.dart in Readme

1.1.1+1: #

1.1.1+2: #

1.1.1+3: #

Fixed dart.pub health: DO use curly braces for all flow control structures

1.1.1+4 #

Fixed LatLngBounds variable names Fixed toBounds method, variables in return were inverted

1.2.0+0: #

1.2.0+1: #

1.2.0+2: #

Fixed Readme

Added: https://pub.dev/packages/poly package for replacing Google's containsLocation function for compiler reasons, google java code could not behave as expected, replacing by new algorithm from Poly package fixed the issue, thanks https://github.com/nicolascav for the feedback.

Added https://github.com/nicolascav code as example on example.dart

1.2.0+3: #

Replaced LatLng for Point class, kept LatLngBounds class

example/example.dart

import 'package:google_maps_utils/google_maps_utils.dart';
import 'package:poly/poly.dart';

void main() {
  Point from = Point(0.0, 0.0);
  Point to = Point(10.0, 5.0);
  Point randomPoint = Point(-23.54545, -23.898098);

  double distance = SphericalUtils.computeDistanceBetween(from, to);
  print('Distance: $distance meters');

  double heading = SphericalUtils.computeHeading(from, to);
  print('Heading: $heading degrees');

  double angle = SphericalUtils.computeAngleBetween(from, to);
  print('Angle: $angle degrees');

  double distanceToAB = PolyUtils.distanceToLine(randomPoint, from, to);
  print('Distance to Line: $distanceToAB meters');

  /// Distance: 1241932.6430813475
  /// Heading: 26.302486345342523
  /// Angle: 0.19493500057547358
  /// Distance to Line: 3675538.1518512294

  /// See grid path on: https://developers.google.com/maps/documentation/utilities/polylinealgorithm

  List<Point> path = PolyUtils.decode(
      'wjiaFz`hgQs}GmmBok@}vX|cOzKvvT`uNutJz|UgqAglAjr@ijBz]opA|Vor@}ViqEokCaiGu|@byAkjAvrMgjDj_A??ey@abD');

  print('path size length: ${path.length}');

  List<Point> simplifiedPath = PolyUtils.simplify(path, 5000);
  String simplifiedPathEncoded = PolyUtils.encode(simplifiedPath);

  print('simplified path: $simplifiedPathEncoded');
  print('path size simplified length: ${simplifiedPath.length}');

  /// Example by: https://github.com/nicolascav
  Point point = Point(-31.623060136389135, -60.68669021129609);

  /// Triangle
  List<Point> polygon = [
    Point(-31.624115, -60.688734),
    Point(-31.624115, -60.684657),
    Point(-31.621594, -60.686717),
    Point(-31.624115, -60.688734),
  ];

  bool contains = PolyUtils.containsLocationPoly(point, polygon);
  print('point is inside polygon?: $contains');

  /// And Many more
}

Use this package as a library

1. Depend on it

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


dependencies:
  google_maps_utils: ^1.2.0+3

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_maps_utils/google_maps_utils.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
34
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]
67
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
poly ^1.0.7+2 1.0.7+2
stack ^0.1.0 0.1.0
Transitive dependencies
collection 1.14.12
csv 4.0.3