Geodesic routines from GeographicLib
This documentation applies to version 1.49.
The documentation for other versions is available at https://geographiclib.sourceforge.io/m.nn/js for versions numbers m.nn ≥ 1.45.
Licensed under the MIT/X11 License; see LICENSE.txt.
$ npm install geographiclib $ node > var GeographicLib = require("geographiclib");
The npm package includes a test suite. Run this by
$ cd node_modules/geograliblib $ npm test
Both of these prescriptions define a GeographicLib namespace.
Now geodesic calculations can be carried out, for example,
var geod = GeographicLib.Geodesic.WGS84, r; // Find the distance from Wellington, NZ (41.32S, 174.81E) to // Salamanca, Spain (40.96N, 5.50W)... r = geod.Inverse(-41.32, 174.81, 40.96, -5.50); console.log("The distance is " + r.s12.toFixed(3) + " m."); // This prints "The distance is 19959679.267 m." // Find the point 20000 km SW of Perth, Australia (32.06S, 115.74E)... r = geod.Direct(-32.06, 115.74, 225, 20000e3); console.log("The position is (" + r.lat2.toFixed(8) + ", " + r.lon2.toFixed(8) + ")."); // This prints "The position is (32.11195529, -63.95925278)."
Two examples of this library in use are
Implementations in various languages
- git repository
- C++ (complete library): documentation, download;
- C (geodesic routines): documentation, also included with recent versions of proj.4;
- Fortran (geodesic routines): documentation;
- Java (geodesic routines): Maven Central package, documentation;
- Python (geodesic routines): PyPI package, documentation;
- Matlab/Octave (geodesic and some other routines): Matlab Central package, documentation;
- C# (.NET wrapper for complete C++ library): documentation.
Version 1.49 (released 2017-10-05)
- Use explicit test for nonzero real numbers.
Version 1.48 (released 2017-04-09)
- Change default range for longitude and azimuth to (−180°, 180°] (instead of [−180°, 180°)).
Version 1.47 (released 2017-02-15)
- Improve accuracy of area calculation (fixing a flaw introduced in version 1.46).
Version 1.46 (released 2016-02-15)
- Fix bugs in PolygonArea.TestEdge (problem found by threepointone).
- Add Geodesic.DirectLine, Geodesic.ArcDirectLine, Geodesic.GenDirectLine, Geodesic.InverseLine, GeodesicLine.SetDistance, GeodesicLine.SetArc, GeodesicLine.GenSetDistance, GeodesicLine.s13, GeodesicLine.a13.
- More accurate inverse solution when longitude difference is close to 180°.
- algorithms + js code: Charles Karney (firstname.lastname@example.org)
- node.js port: Yurij Mikhalevich (email@example.com)