Skip to content

Calculate the great circle distance on the Earth having a pair of latitude/longitude points

License

Notifications You must be signed in to change notification settings

fliverdev/great_circle_distance

 
 

Repository files navigation

Great Circle Distance Pub Travis status Coverage Status

Updated to work with Flutter 1.9 and Dart 2.5

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.

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

About

Calculate the great circle distance on the Earth having a pair of latitude/longitude points

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 100.0%