我正在尝试借助用户的纬度,经度和公式来查询纬度,经度的地方。
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.
谁可以提供帮助?
答案 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)