简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM