{"id":21377,"library":"geographiclib-geodesic","title":"geographiclib-geodesic","description":"JavaScript implementation of the geodesic routines from GeographicLib for solving direct and inverse geodesic problems on an ellipsoid of revolution. Current stable version is 2.2.0, released on 2025-01-01 with monthly releases. Key differentiators: high accuracy (nanometer precision), pure JavaScript with no native dependencies, TypeScript types included, supports both ESM and CJS. Used for distance, azimuth, and destination calculations on the WGS84 ellipsoid and other reference ellipsoids. Split from monolithic geographiclib package in v2.0.0 into this and geographiclib-dms.","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/geographiclib/geographiclib-js","tags":["javascript","geodesics","geometry","geographiclib","geography","geodesic problem","direct geodesic problem","inverse geodesic problem","geodesic calculator","typescript"],"install":[{"cmd":"npm install geographiclib-geodesic","lang":"bash","label":"npm"},{"cmd":"yarn add geographiclib-geodesic","lang":"bash","label":"yarn"},{"cmd":"pnpm add geographiclib-geodesic","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"optional dependency for parsing and formatting DMS coordinates (degrees-minutes-seconds)","package":"geographiclib-dms","optional":true}],"imports":[{"note":"ESM import since v2.0.0. CommonJS require works but without destructuring.","wrong":"const Geodesic = require('geographiclib-geodesic').Geodesic","symbol":"Geodesic","correct":"import { Geodesic } from 'geographiclib-geodesic'"},{"note":"WGS84 is a static property, not a named export. Use Geodesic.WGS84 or new Geodesic('WGS84').","wrong":"import { WGS84 } from 'geographiclib-geodesic'","symbol":"WGS84","correct":"const { Geodesic } = require('geographiclib-geodesic'); const geod = Geodesic.WGS84;"},{"note":"Default import gives the whole module. Not recommended; prefer named imports.","wrong":"","symbol":"default import","correct":"import geographiclib from 'geographiclib-geodesic'"}],"quickstart":{"code":"import { Geodesic } from 'geographiclib-geodesic';\n\nconst geod = Geodesic.WGS84;\n\n// Inverse problem: distance and azimuth between two points\nconst r1 = geod.Inverse(-41.32, 174.81, 40.96, -5.50);\nconsole.log(`Distance: ${r1.s12.toFixed(3)} m`);\nconsole.log(`Azimuth from A: ${r1.azi1.toFixed(8)}°`);\nconsole.log(`Azimuth from B: ${r1.azi2.toFixed(8)}°`);\n\n// Direct problem: point given start point, azimuth, and distance\nconst r2 = geod.Direct(-32.06, 115.74, 225, 20000e3);\nconsole.log(`Destination: (${r2.lat2.toFixed(8)}, ${r2.lon2.toFixed(8)})`);\nconsole.log(`Final azimuth: ${r2.azi2.toFixed(8)}°`);\n\n// Polygon area (example: simple triangle)\nconst geodPoly = Geodesic.WGS84;\nconst poly = geodPoly.Polygon(false);\npoly.AddPoint(0, 0);\npoly.AddPoint(1, 0);\npoly.AddPoint(0, 1);\nconst result = poly.Compute();\nconsole.log(`Perimeter: ${result.perimeter.toFixed(3)} m`);\nconsole.log(`Area: ${result.area.toFixed(3)} m²`);","lang":"typescript","description":"Solves inverse geodesic (distance & azimuth between two points) and direct geodesic (destination from point, azimuth, distance) using WGS84 ellipsoid, plus polygon area computation."},"warnings":[{"fix":"Update imports: use 'geographiclib-geodesic' for geodesic functions and optionally 'geographiclib-dms' for DMS conversion. The old 'geographiclib' package will be deprecated after 2023-05-01.","message":"Version 2.0.0 split from monolithic geographiclib package. Imports changed from 'geographiclib' to 'geographiclib-geodesic' and 'geographiclib-dms'.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"For ESM: use import { Geodesic } from 'geographiclib-geodesic'. For CJS: use const { Geodesic } = require('geographiclib-geodesic').","message":"In v2.0.0, ES module support was added. The package now exports ESM by default. CommonJS require still works but may behave differently in some bundlers.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace require('geographiclib') with require('geographiclib-geodesic') and if using DMS, add require('geographiclib-dms').","message":"The old monolithic package 'geographiclib' (which included DMS functions) is deprecated after 2023-05-01. Users should migrate to 'geographiclib-geodesic' and optionally 'geographiclib-dms'.","severity":"deprecated","affected_versions":"all versions of geographiclib"},{"fix":"Use Geodesic.WGS84 after importing { Geodesic }.","message":"Geodesic.WGS84 is a static property on the Geodesic class, not a separate export. Trying to import { WGS84 } directly fails.","severity":"gotcha","affected_versions":"all"},{"fix":"Always store the result and access the needed properties. See documentation for complete list.","message":"The Direct and Inverse methods return objects with many properties (lat2, lon2, azi1, azi2, s12, etc.). Not reading the full result may lead to missing azimuth or distance values.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure inputs are in degrees and meters as expected. Convert if necessary.","message":"Coordinates are in degrees; azimuths are in degrees from north (clockwise). Distances are in meters. No unit conversion is performed.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'npm install geographiclib-geodesic' and ensure import path is correct: require('geographiclib-geodesic') or import { Geodesic } from 'geographiclib-geodesic'.","cause":"Package not installed or incorrect import path after split from geographiclib.","error":"Cannot find module 'geographiclib-geodesic'"},{"fix":"Install 'geographiclib-geodesic' and import { Geodesic } from 'geographiclib-geodesic'.","cause":"Using outdated import from the deprecated 'geographiclib' package where Geodesic was not available.","error":"Geodesic.WGS84 is undefined"},{"fix":"Ensure you are using a bundler that supports ESM (e.g., webpack 5 with experiments.outputModule) or use CommonJS require(). Alternatively, use the browser-ready file from 'geographiclib-geodesic/geographiclib-geodesic.min.js'.","cause":"Webpack may not resolve the package correctly if it's not configured for ESM or if there is a version mismatch.","error":"import { Geodesic } from 'geographiclib-geodesic' works in Node but not in browser (with webpack or parcel)"},{"fix":"Use const geod = require('geographiclib-geodesic').Geodesic.WGS84 or import { Geodesic } from 'geographiclib-geodesic'; const geod = Geodesic.WGS84;","cause":"The geod object is not a Geodesic instance but the module itself (require returns the whole module).","error":"TypeError: geod.Inverse(...) is not a function or returns undefined"},{"fix":"Check that latitudes are between -90 and 90, longitudes between -180 and 180, azimuth between 0 and 360, distance positive finite.","cause":"Input coordinates out of range or azimuth/distance not finite.","error":"Result latitude is NaN or longitude is NaN"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}