Skip to content

Geographic distances ​

great_circle_distance calculates the shortest spherical surface distance between two longitude/latitude positions. It returns metres using a sphere with radius 6,371,000 metres.

The result describes a geographic arc, rather than a road route or an ellipsoidal distance.

Syntax ​

text
great_circle_distance(longitude1, latitude1, longitude2, latitude2)

Arguments ​

Longitudes are in degrees from -180 through 180. Latitudes are in degrees from -90 through 90. Coordinates must satisfy those ranges; SQL NULL propagates.

Returned value ​

An approximate floating-point distance in metres. Identical positions return zero.

Examples ​

One degree north along a meridian ​

sql
SELECT round(great_circle_distance(0, 0, 0, 1)) AS metres
FORMAT csv;
text
111195.0

Identical positions ​

sql
SELECT great_circle_distance(10, 20, 10, 20)
FORMAT csv;
text
0.0

See geometry construction for typed coordinate collections.