geodesy 0.3.0

geodesy #

A Dart library for implementing geodesic and trigonometric calculations based on a spherical Earth model for working with points and paths such as distances, bearings and destinations

Getting Started #

Add the following line in your pubspec file #


Include the widget in your dart file #

import 'package:geodesy/geodesy.dart';

Usage #

Geodesy() #

Geodesy geodesy = Geodesy();

LatLng(double latitude, double longitude) #

LatLng l = LatLng(22.308, 114.1716);

Methods #

destinationPointByDistanceAndBearing(LatLng l, num distance, num bearing, num radius) #

Calculate a destination point given the distance and bearing. If raduis is not specified, Earth radius will be used.

LatLng distinationPoint = geodesy.destinationPointByDistanceAndBearing(l3, 2400, 420.2, null);

midPointBetweenTwoGeoPoints(LatLng l1, LatLng l2) #

Calcuate the midpoint bewteen teo geo points.

LatLng midpoint = geodesy.midPointBetweenTwoGeoPoints(l1, l2);

distanceBetweenTwoGeoPoints(LatLng l1, LatLng l2, num radius) #

Calculate the distance in meters between two geo points. If raduis is not specified, Earth radius will be used.

num distance = geodesy.distanceBetweenTwoGeoPoints(l1, l2, null);

bearingBetweenTwoGeoPoints(LatLng l1, LatLng l2) #

Calculate the bearing from point l1 to point l2.

num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l1, l2);

finalBearingBetweenTwoGeoPoints(LatLng l1, LatLng l2) #

Calculate the final bearing from point l1 to point l2.

num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l1, l2);

degreesToRadians(num degrees) #

Convert degrees to radians

num l1LatRadians = degreesToRadians(;

radiansToDegrees(num radians) #

Convert degrees to radians

num degrees = radiansToDegrees(latRadians);

isGeoPointInBoudingBox(LatLng l, LatLng topLeft, LatLng bottomRight) #

Check if a given geo point is in the bouding box

bool inBoudingBox = geodesy.isGeoPointInBoudingBox(l1, l2, l3);

intersectionByPaths(LatLng l1, LatLng l2, num b1, num b2) #

Calculate the geo point of intersection of two given paths

LatLng intersectionByPaths = geodesy.intersectionByPaths(l1, l2, b1, b2);

crossTrackDistanceTo(LatLng l1, LatLng start, LatLng end, num radius) #

Calculate signed distance from a geo point to greate circle with start and end points

num distanceToGreatCircle = geodesy.crossTrackDistanceTo(l1, l2, l3, null);

isGeoPointInPolygon(LatLng l, List

Check if a given geo point is in the a polygon using even-odd rule algorithm

bool isGeoPointInPolygon = geodesy.isGeoPointInPolygon(l, poly);


0.3.0 #

  • Added latlong package
  • Deprecated LatLng
  • Deprecated degreesToRadians & radiansToDegrees

0.2.0 #

  • Added intersectionByPaths
  • Added crossTrackDistanceTo
  • Added isGeoPointInPolygon

0.1.1 #

  • Added example
  • Reformatted with Dart Style

0.1.0 #

  • Initial version, created by wingkwong


import '../lib/geodesy.dart';

main() async {
  Geodesy geodesy = Geodesy();
  LatLng l1 = LatLng(50.06638889, 5.71472222);
  LatLng l2 = LatLng(58.64388889, 3.07000000);

  num distance = geodesy.distanceBetweenTwoGeoPoints(l1, l2, null);
  print("[distanceBetweenTwoGeoPoints] Distance: " + distance.toString());

  LatLng l3 = LatLng(51.4778, -0.0015);
  LatLng distinationPoint =
      geodesy.destinationPointByDistanceAndBearing(l3, 7794.0, 300.7, null);
  print("[destinationPointByDistanceAndBearing] Lat: " +
  print("[destinationPointByDistanceAndBearing] Lng: " +

  LatLng l4 = LatLng(52.205, 0.119);
  LatLng l5 = LatLng(48.857, 2.351);
  num bearing = geodesy.bearingBetweenTwoGeoPoints(l4, l5);
  print("[bearingBetweenTwoGeoPoints] Bearing: " + bearing.toString());

  num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l4, l5);
  print("[finalBearingBetweenTwoGeoPoints] Bearing:" + finalBearing.toString());

  LatLng midpoint = geodesy.midPointBetweenTwoGeoPoints(l4, l5);
  print("[midPointBetweenTwoGeoPoints] Midpoint Lat: " +
  print("[midPointBetweenTwoGeoPoints] Midpoint Lng: " +

  bool inBoudingBox = geodesy.isGeoPointInBoudingBox(l3, l5, l4);
  print("[isGeoPointInBoudingBox]: " + inBoudingBox.toString());

  num b1 = 108.547;
  num b2 = 32.435;
  LatLng intersectionByPaths = geodesy.intersectionByPaths(l4, l5, b1, b2);
      "[intersectionByPaths] Lat: " + intersectionByPaths.latitude.toString());
      "[intersectionByPaths] Lng: " + intersectionByPaths.longitude.toString());

  LatLng l6 = LatLng(50.587, 1.231);
  num distanceToGreatCircle = geodesy.crossTrackDistanceTo(l4, l5, l6, null);
  print("[crossTrackDistanceTo] :" + distanceToGreatCircle.toString());

  List<LatLng> poly = [
    LatLng(1.0, 1.0),
    LatLng(1.0, 2.0),
    LatLng(2.0, 2.0),
    LatLng(2.0, 1.0)
  LatLng l7 = LatLng(1.5, 1.5);
  bool isGeoPointInPolygon = geodesy.isGeoPointInPolygon(l7, poly);
  print("[isGeoPointInPolygon] :" + isGeoPointInPolygon.toString());

Use this package as a library

1. Depend on it

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

  geodesy: ^0.3.0

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:geodesy/geodesy.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 Jul 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19


Detected platforms: Flutter, web, other

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

Health suggestions

Format lib/geodesy.dart.

Run dartfmt to format lib/geodesy.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
latlong ^0.6.1 0.6.1
Transitive dependencies
ansicolor 1.0.2
console_log_handler 1.1.6
intl 0.15.8
logging 0.11.3+2
path 1.6.2
validate 1.7.0