尝试通过用户纬度,经度和位置纬度,经度查询postgres中最近的地方

时间:2020-11-10 16:22:01

标签: postgresql

我正在尝试借助用户的纬度,经度和公式来查询纬度,经度的地方。

SELECT * FROM place
WHERE acos(sin(0.90987) * sin(latitude) +
      cos(0.9098) * cos(latitude) * cos(0.3675-longitude)) * 6371
      <= 100;

但是我收到错误消息:

Error: Input is out of range.

谁可以提供帮助?

input is out of range

1 个答案:

答案 0 :(得分:1)

假设坐标以弧度为单位,则在结尾附近有一个错字(-longitude必须在最后一个cos之外)

SELECT * FROM place 
WHERE 
 acos(
   sin(0.90987)
    *sin(latitude)
   +cos(0.9098)
     *cos(latitude)
     *cos(0.3675)
   -longitude)
*6371<=100

话虽如此,看看Postgis,它大大简化了空间查询 Select * FROM place where st_dwithin(place.geog, my_target_point, 100)

相关问题