How can I get the distance between two points on Earth from PostGIS?

I get an unexpected value from a PostGIS distance request, and I'm not sure why. I am trying to find the distance between two points on Earth.

SELECT ST_Distance(
  ST_Point(50.7678,6.091499)::geography,
  ST_Point(52.525592,13.369545)::geography
) as distance;

... returns 827757.672533206, or about 827.7 km.

However, if I calculate this distance using the open source library that I use, or using any of several online calculators, I get 538.6km. Something is clearly wrong.

What am I doing wrong?

+4
source share
1 answer

The result is correct, the input is not. ST_Point accepts input as (lon,lat)while you check how (lat,lon).

+5
source

All Articles