great_circle_distance 1.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 85

Great-circle distance Pub Travis status Coverage Status

Calculate the great-circle distance between two points (having Latitude,Longitude) on the surface of Earth You can get the distance using the Spherical law of cosines, Haversine formula or Vincenty`s formula

The great-circle distance is the shortest distance between two points on the surface of a sphere

Great-circle distance (drawn in red) between two points on a sphere

A diagram illustrating great-circle distance (drawn in red) between two points on a sphere, P and Q. Two antipodal points, u and v, are also depicted. <br><br> By CheCheDaWaff (Own work) [CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0)], via Wikimedia Commons

Included in this library:

  • Spherical law of cosines
  • Haversine formula
  • Vincenty` formula (por from the Android implementation)

Disclaimer: The earth is not quite a sphere. This means that errors(0.3%,0.5% errors) from assuming spherical geometry might be considerable depending on the points; so: don't trust your life on this value

Usage example:

final lat1 = 41.139129;
final lon1 = 1.402244;

final lat2 = 41.139074;
final lon2 = 1.402315;

var gcd = new GreatCircleDistance.fromDegrees(latitude1: lat1, longitude1: lon1, latitude2: lat2, longitude2: lon2);

print('Distance from location 1 to 2 using the Haversine formula is: ${gcd.haversineDistance()}');
print('Distance from location 1 to 2 using the Spherical Law of Cosines is: ${gcd.sphericalLawOfCosinesDistance()}');
print('Distance from location 1 to 2 using the Vicenty`s formula is: ${gcd.vincentyDistance()}');

Check Wikipedia for detailed description on Great-circle distance

Changelog

0.0.1

  • Initial version for the great-circle distance (Spherical law of cosines, Haversine formula and Vincenty` formula)

0.0.2

  • Minor update to sample code

0.0.3

  • Add an usage example the the README

0.0.5

  • Update descriptions

0.0.6

  • Minor test update, added travis integration

1.0.0

Added coordinates validation. A coordinate is considered invalid if it meets at least one of the following criteria:

  • Its latitude is greater than 90 degrees or less than -90 degrees.
  • Its longitude is greater than 180 degrees or less than -180 degrees.

see Decimal degrees

1.0.1

Remove upper bound Dart SDK constraint

thanks to @bramvbilsen for pointing it out and for the PR

example/great_circle_distance_example.dart

import 'package:great_circle_distance/great_circle_distance.dart';

main() {
    final lat1 = 41.139129;
    final lon1 = 1.402244;

    final lat2 = 41.139074;
    final lon2 = 1.402315;

    var gcd = new GreatCircleDistance.fromDegrees(
        latitude1: lat1, longitude1: lon1, latitude2: lat2, longitude2: lon2);

    print(
        'Distance from location 1 to 2 using the Haversine formula is: ${gcd.haversineDistance()}');
    print('Distance from location 1 to 2 using the Spherical Law of Cosines is: ${gcd
        .sphericalLawOfCosinesDistance()}');
    print(
        'Distance from location 1 to 2 using the Vicenty`s formula is: ${gcd.vincentyDistance()}');
}

1. Depend on it

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


dependencies:
  great_circle_distance: "^1.0.1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:great_circle_distance/great_circle_distance.dart';
        
Version Uploaded Documentation Archive
1.0.1 Feb 8, 2018 Go to the documentation of great_circle_distance 1.0.1 Download great_circle_distance 1.0.1 archive
1.0.0 Oct 12, 2017 failed Download great_circle_distance 1.0.0 archive
0.0.6 Oct 7, 2017 Go to the documentation of great_circle_distance 0.0.6 Download great_circle_distance 0.0.6 archive
0.0.5 Oct 7, 2017 Go to the documentation of great_circle_distance 0.0.5 Download great_circle_distance 0.0.5 archive
0.0.4 Oct 7, 2017 Go to the documentation of great_circle_distance 0.0.4 Download great_circle_distance 0.0.4 archive
0.0.3 Oct 1, 2017 Go to the documentation of great_circle_distance 0.0.3 Download great_circle_distance 0.0.3 archive
0.0.2 Oct 1, 2017 Go to the documentation of great_circle_distance 0.0.2 Download great_circle_distance 0.0.2 archive
0.0.1 Oct 1, 2017 Go to the documentation of great_circle_distance 0.0.1 Download great_circle_distance 0.0.1 archive

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

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

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:great_circle_distance/great_circle_distance.dart.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 8 hints.

    Run dartfmt to format lib/great_circle_distance.dart.

    Run dartfmt to format lib/src/formula/harvesine.dart.

    Similar analysis of the following files failed:

    • lib/src/formula/spherical_lawofcosines.dart (hint)
    • lib/src/formula/vincenty.dart (hint)
    • lib/src/great_circle_distance_base.dart (hint)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
Dev dependencies
test ^0.12.0