haversine 1.0.2

  • README.md
  • Example
  • Installing
  • Versions
  • 78

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.



  • Initial version for calculating geographic distance using the Haversine formula


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


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


Update tests


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 packages get

Alternatively, your editor might support pub get or flutter packages 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';
Version Uploaded Documentation Archive
1.0.2 Feb 10, 2018 Go to the documentation of haversine 1.0.2 Download haversine 1.0.2 archive
1.0.1 Oct 12, 2017 Go to the documentation of haversine 1.0.1 Download haversine 1.0.1 archive
1.0.0 Oct 12, 2017 Go to the documentation of haversine 1.0.0 Download haversine 1.0.0 archive
0.0.2 Oct 1, 2017 Go to the documentation of haversine 0.0.2 Download haversine 0.0.2 archive
0.0.1 Sep 30, 2017 Go to the documentation of haversine 0.0.1 Download haversine 0.0.1 archive
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 Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7


Detected platforms: Flutter, web, other

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

Health issues and suggestions

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

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

line 72 col 68: Undefined name 'PI'.

Document public APIs (-9.23 points)

12 out of 13 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Format lib/haversine.dart.

Run dartfmt to format lib/haversine.dart.


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