JSDoc: Home (original) (raw)

Geodesic and DMS routines from GeographicLib

This documentation applies to version 2.1.0.

The documentation for other versions is available athttps://geographiclib.sourceforge.io/JavaScript.

Licensed under the MIT/X11 License; see LICENSE.txt.

These packages are a JavaScript implementations of the geodesic and DMS routines from GeographicLib. The two packages are

Prior to version 2.0.0, these were combined in a single packagegeographiclib. Because the geodesic and DMS components of this package were independent and because most users will primarily be interested in the geodesic calculations, it made sense to separate them into two packages; removal of the DMS routines from geographiclib-geodesic reduced it size by about 20%. The geographiclib package was be deprecated on 2023-05-01.

Installation

The libraries can be used in node by first installing the packages with npm

$ npm install geographiclib-geodesic geographiclib-dms
$ node
> var geodesic = require("geographiclib-geodesic");
> var DMS = require("geographiclib-dms");

The npm packages include test suites. Run this by, e.g.,

$ cd node_modules/geographiclib-geodesic
$ npm test

Alternatively, you can use it in client-side JavaScript, by including in your HTML page

<script
  type="text/javascript"
  src="https://geographiclib.sourceforge.io/scripts/geographiclib-geodesic.min.js">
</script>
<script
  type="text/javascript"
  src="https://geographiclib.sourceforge.io/scripts/geographiclib-dms.min.js">
</script>

Both of these prescriptions bring geodesic andDMS into scope.

Examples

Now geodesic calculations can be carried out, for example,

var geod = geodesic.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

More information

Change log

Authors