GeographicLib  1.45
Implementations in other languages
Back to Code organization. Forward to Geoid height. Up to Contents.

Implementations of subsets of GeographicLib are available in other languages

C and Fortran implementation

The directories legacy/C and legacy/Fortran contain implementations of Geodesic, GeodesicLine, and PolygonAreaT in C and Fortran respectively. These are intended for use in old codes written in these languages and should work any reasonably modern compiler. These implementations are entirely self-contained and do not depend on the rest of GeographicLib. Sample main programs to solve the direct and inverse geodesic problems and to compute polygonal areas are provided.

For documentation, see

Java implementation

The directory java contains implementations of Geodesic, GeodesicLine, and PolygonAreaT in Java. This implementation is entirely self-contained and does not depend on the rest of GeographicLib. Sample main programs to solve the direct and inverse geodesic problems and to compute polygonal areas are provided.

This package is available on Maven Central; so if you're using Apache Maven as your build system, you can use this package by including the dependency


in your pom.xml.

For documentation, see

JavaScript implementation

The directory js/src contains the classes

translated into JavaScript. When GeographicLib is built the JavaScript source files are concatenated and compressed into a single file geographiclib.min.js. This can be included into your document with

<script type="text/javascript"

This file gives you the latest version of the library. If you need to use a specific version of this file, include a version number as in

<script type="text/javascript"

You can visit to see which versions are available.

Starting with version 1.45, this package is available as an node package that can be installed with npm (thanks to Yurij Mikhalevich for help with this work). To install this as a node package, use

  npm install geographiclib 

For documentation, see

Examples of using this interface are

Python implementation

A Python implementation of the geodesic routines from GeographicLib are provided in the python/geographiclib directory (which is installed as PREFIX/lib/python/site-packages/geographiclib, if COMMON_INSTALL_PATH is ON, and as PREFIX/python/geographiclib, otherwise). This contains implementations of the classes

You can install the Python interface independent of the rest of GeographicLib using pip

  pip install geographiclib 

This requires root privileges and you might first need to install the python-pip package.

Alternatively download

and unpack the .tar.gz or .zip file. You can "install" these routines, so that they are in python's default path with, for example

  cd geographiclib-1.16
  python install

(this will require root privileges). Or else you can set the path within Python using

1 >>> import sys
2 >>> sys.path.append("/usr/local/lib/python/site-packages")

An example of using this interface is

1 >>> from geographiclib.geodesic import Geodesic
2 >>> # The geodesic inverse problem
3 ... Geodesic.WGS84.Inverse(-41.32, 174.81, 40.96, -5.50)
4 >>> # The geodesic direct problem
5 ... Geodesic.WGS84.Direct(40.6, -73.8, 45, 10000e3)
6 >>> # How to obtain several points along a geodesic
7 ... line = Geodesic.WGS84.Line(40.6, -73.8, 45)
8 >>> line.Position( 5000e3)
9 >>> line.Position(10000e3)
10 >>> # Computing the area of a geodesic polygon
11 ... def p(lat,lon): return {'lat': lat, 'lon': lon}
12 ...
13 >>> Geodesic.WGS84.Area([p(0, 0), p(0, 90), p(90, 0)])
14 >>> # Introductory help
15 ... help(Geodesic)

Another illustrative exercise is finding the point midway between JFK Airport to Singapore Changi Airport

1 from geographiclib.geodesic import Geodesic
3 # Coordinates of airports
4 lat1, lon1 = 40.640, -73.779 # JFK
5 lat2, lon2 = 1.359, 103.989 # SIN
7 # Compute path from 1 to 2
8 g = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2)
10 # Compute midpoint starting at 1
11 h = Geodesic.WGS84.Direct(lat1, lon1, g['azi1'], g['s12']/2)
12 print(h['lat2'], h['lon2'])

(Note: The initial version of was provided by Andrew MacIntyre of the Australian Communications and Media Authority.)

MATLAB and Octave implementations

The matlab/geographiclib directory contains MATLAB and Octave implementations of some of the functions of GeographicLib. To use these, start MATLAB or Octave and run one of (for example):

   addpath /usr/local/share/matlab/geographiclib
   addpath C:/pkg-vc10-x64/GeographicLib-1.45/matlab/geographiclib

A summary of the routines is obtained by

   help geographiclib 

These MATLAB functions is also available from the MATLAB File Exchange site as the GeographicLib toolbox, package 50605.

The functions fall into the following groups

These functions reimplement the C++ routines from GeographicLib in MATLAB code (but note that routines for great ellipses are only available as MATLAB code). Because these functions are all vectorized, their performance is comparable to the C++ routines. The minimum version numbers required are

In addition, in order to use the geoid routines, Octave needs to have been built with a version of GraphicsMagick which supports 16-bit images.

Previously, some of these routines were packaged as three separate packages

These packages have now all been incorporated into the GeographicLib toolbox.

Prior to version 1.42, GeographicLib was distributed with some MATLAB functionality offered via compiled interface code. This has now been replaced by native MATLAB wrapper functions which call the functions in the GeographicLib toolbox. To use these wrapper functions, run one of:

   addpath /usr/local/share/matlab/geographiclib-legacy
   addpath C:/pkg-vc10-x64/GeographicLib-1.45/matlab/geographiclib-legacy

The GeographicLib toolbox must also be in your MATLAB path. A summary of the routines is obtained by

   help geographiclib-legacy 

These functions are DEPRECATED. Here is a function listing

The last routine can be used to compile the obsolete interface code (which is still provided as C++ code in the same directory). Doing this will switch MATLAB from using the native MATLAB routines to the compiled interface. However, the native code is easier to deploy and is about as fast; so the compiled interface will be removed at some point in 2016.

Maxima routines

Maxima is a free computer algebra system which can be downloaded from Maxima was used to generate the series used by TransverseMercator (tmseries.mac), Geodesic (geod.mac), Rhumb (rhumbarea.mac), The area under a great ellipse (gearea.mac), the relation between Auxiliary latitudes (auxlat.mac), and to generate accurate data for testing (tm.mac and geodesic.mac). The latter uses Maxima's bigfloat arithmetic together with series extended to high order or solutions in terms of elliptic integrals (ellint.mac). These files contain brief instructions on how to use them.

.NET wrapper

This is a comprehensive wrapper library, written and maintained by Scott Heiman, which exposes all of the functionality of GeographicLib to the .NET family of languages. For documentation, see

Back to Code organization. Forward to Geoid height. Up to Contents.