{distance:lat1:lon1:lat2:lon2}

Description

Returns the great-circle distance in whole metres between two points on Earth, each given as a latitude and longitude in decimal degrees. The calculation uses the haversine formula on a sphere of radius 6371000 metres (the mean Earth radius), so it is the as-the-crow-flies distance, not a road or route distance. The four arguments are, in order, the latitude and longitude of the first point and the latitude and longitude of the second point. Use positive values for north and east, negative for south and west. Each argument is evaluated as a math expression (the same evaluator as the math command), so arithmetic and a decimal comma both work; anything that is not a number evaluates to zero. The result is truncated to a whole number of metres. To show kilometres, wrap the call in the math command and divide by 1000.

Parameters

lat1 required

Latitude of the first point in decimal degrees (positive north, negative south). The value is evaluated as a math expression, so plain numbers and arithmetic both work; a comma is read as a decimal point.

lon1 required

Longitude of the first point in decimal degrees (positive east, negative west). Evaluated as a math expression; commas act as decimal points.

lat2 required

Latitude of the second point in decimal degrees. Same rules as lat1.

lon2 required

Longitude of the second point in decimal degrees. Same rules as lon1.

Examples

test{distance:50.0898689:14.4000936:48.8940964:13.8241719}
Expected139317
Actual139317
The four arguments are latitude and longitude of the first point, then latitude and longitude of the second point, all in decimal degrees. The result is the great-circle (as-the-crow-flies) distance in whole metres.
test{distance:50.087:14.421:50.087:14.421}
Expected0
Actual0
Two identical coordinates are zero metres apart.
test{distance:0:0:1:0}
Expected111194
Actual111194
One degree of latitude is about 111 kilometres anywhere on Earth. The result is metres, truncated to a whole number.
test{distance:50,0755:14,4378:49,1951:16,6068}
Expected184332
Actual184332
Coordinates may use a comma as the decimal separator; each argument is passed through the same evaluator as {math}, which reads a comma as a decimal point. Prague to Brno is about 184 km in a straight line.
test{distance:50+0.0898689:14.4000936:48.8940964:13.8241719}
Expected139317
Actual139317
Each argument is evaluated as a math expression before the distance is computed, so 50+0.0898689 is the same as writing 50.0898689 directly.
test{math:{distance:50.0755:14.4378:49.1951:16.6068}/1000:1}
Expected184.3
Actual184.3
{distance:} returns metres. Wrap it in {math:} to divide by 1000 and round to one decimal place for a kilometre figure.