试图计算PostgreSQL中两个lat lng点之间的距离-PostgreSQL earth_box(ll_to_earth)返回值的单位是多少?

试图计算PostgreSQL中两个lat lng点之间的距离-PostgreSQL earth_box(ll_to_earth)返回值的单位是多少?,sql,postgresql,distance,geography,earthdistance,Sql,Postgresql,Distance,Geography,Earthdistance,我有这样一个问题: SELECT * FROM chat_rooms WHERE earth_box(ll_to_earth(5, 5), 111000) @> ll_to_earth(lat, lng); 基本上,我在查询中有lat=lng=5,在我的chat___房间表中有两个条目,一个是lat=lng=5,另一个是lat=lng=4。使用在线计算器,这两个条目之间的距离为157英里=252.667公里(即,当半径>=157英里时,应返回条目lat=lng=4。但是,当半径指定为~

我有这样一个问题:

SELECT * FROM chat_rooms 
WHERE earth_box(ll_to_earth(5, 5), 111000) @> ll_to_earth(lat, lng);
基本上,我在查询中有
lat=lng=5
,在我的
chat___房间
表中有两个条目,一个是
lat=lng=5
,另一个是
lat=lng=4
。使用在线计算器,这两个条目之间的距离为157英里=252.667公里(即,当半径>=157英里时,应返回条目
lat=lng=4
。但是,当半径指定为~111000+时,查询仅返回带有
lat=lng=4
的条目。我的问题是,半径的单位是什么,我是否正确执行此查询?

根据,默认情况下,半径以米表示

最重要的缺陷是,4;4和5;5之间的距离是157公里,而不是英里。尽管111000米与157000米不同,但
接地盒
的文档显示

此框中的某些点超出指定的大圆 距离该位置,因此使用接地距离进行第二次检查 应包含在查询中

因此,您的查询应该类似于

SELECT * FROM chat_rooms 
WHERE earth_box(ll_to_earth(5, 5), 111000) @> ll_to_earth(lat, lng)
AND earth_distance(ll_to_earth(5,5), ll_to_earth(lat, lng)) <= 111000
从聊天室中选择*
其中接地盒(LLU对地(5,5),111000)@>LLU对地(lat,lng)
和接地距离(ll_至_接地(5,5),ll_至_接地(lat,lng))