Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm getting an unexpected value from a PostGIS distance query, and I'm not sure why. I'm 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.7km.

However, if I calculate this distance with an open source library I'm using, or using any one of several online calculators, I get 538.6km. Something is obviously amiss.

What am I doing wrong?

like image 247
Nathan Long Avatar asked Jul 03 '15 20:07

Nathan Long


Video Answer


1 Answers

The result is correct, the input is not. ST_Point accepts input as (lon,lat) while you're verifying it as (lat,lon).

like image 132
Jakub Kania Avatar answered Oct 11 '22 21:10

Jakub Kania