Geodesy: how to calculate the straight line distance between two locations, which is represented by longitude and latitude?


Is the following the correct way to calculate the straight line distance between two points / locations by longitude and latitude?

julia> using Geodesy
INFO: Precompiling module Geodesy.

julia> x_lla = LLA(-27.468937, 153.023628, 0.0)
LLA(lat=-27.468937°, lon=153.023628°, alt=0.0)

julia> y_lla = LLA(-27.465933, 153.025900, 0.0)
LLA(lat=-27.465933°, lon=153.0259°, alt=0.0)

julia> distance(x_lla, y_lla)

Is there a simple / easy way to transfer the longitude and latitude into the x value and y value (cartesian coordinate system) of a point in a planar map?


A map in what projection?

If you want great circle distance, and are happy to think of the earth as a sphere, then it should just be arccos(dot(v,w)) where v,w are 3-vectors like v=[sin(lat), cos(lat)*sin(long), cos(lat)*cos(long)]… up to units. But perhaps a package called Geodesy will already have this somewhere?


@improbable22, I read the package description of Geodesy and the above example if directly from their git link. But I’m not sure I totally understand it.


Sorry perhaps a reading failure on my part.

Now that I look at the readme, it sounds like “distance” is probably a straight-line distance in 3D. Is this what you want?

They say "Future work may focus on geodesics and related calculations " which is what I was aiming for. But the package is more sophisticated than assuming the world is a sphere, and thus working out the accurate great-circle distance (i.e. geodesic length) accurately would be harder work.


To get the cartesian (2d-) distance on a map, have a look at Proj4.jl which is a Julia wrapper around a relatively widely used C library. As @improbable22 already wrote, this depends on the map projection.


Doesn’t harversine distance in the Distances package work?

using Distances
julia> l1 = (-27.468937, 153.023628)
julia> l2 = (-27.465933, 153.025900)
julia> haversine(l1, l2, 6372.8)

I used it to calculate distances in an agricultural plot.


@alejandromerchan, yes. It’s correct. See