haversine 1.0.2

haversine.dart Pub Travis status Coverage Status

Simple Haversine formula implementation to calculate geographic distance on earth having a pair of Latitude/Longitude points.

The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes.

The formula in this library works on the basis of a spherical earth, which is accurate enough for most purposes.

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

Check this detailed information.

Changelog #

0.0.1 #

  • Initial version for calculating geographic distance using the Haversine formula

0.0.2 #

  • Minor update, now using the WGS84 major axis for the Earth radius

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 #

Update tests

1.0.2 #

Minor update to removee the upper bound sdk limit


// Copyright (c) 2017, yeradis. 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:haversine/haversine.dart';

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

    final lat2 = 41.139074;
    final lon2 = 1.402315;

    final harvesine = new Haversine.fromDegrees(latitude1: lat1,
                                               longitude1: lon1,
                                                latitude2: lat2,
                                               longitude2: lon2);

    print('Distance from location 1 to 2 is : ${harvesine.distance()}');

Use this package as a library

1. Depend on it

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

  haversine: ^1.0.2

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:haversine/haversine.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5

Health issues and suggestions

Fix lib/src/haversine_base.dart. (-26.49 points)

Analysis of lib/src/haversine_base.dart failed with 1 error, 4 hints:

line 72 col 68: Undefined name 'PI'.

line 42 col 13: DO use curly braces for all flow control structures.

line 42 col 19: Unnecessary new keyword.

line 45 col 13: DO use curly braces for all flow control structures.

line 45 col 19: Unnecessary new keyword.

Format lib/haversine.dart.

Run dartfmt to format lib/haversine.dart.

Maintenance issues and suggestions

Package is too old. (-100 points)

The package was last published more than two years ago.


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