haversine 1.0.2

  • README.md
  • Example
  • Installing
  • Versions
  • 75

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()}');

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


This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 10, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1


Describes how popular the package is relative to other packages. [more]
52 / 100
Code health derived from static analysis. [more]
97 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]


Detected platforms: Flutter, web, other

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


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