【发布时间】:2020-11-04 23:35:07
【问题描述】:
在 postgress 中,我有以下函数,它使用基于 Google 地图视口坐标的 ST_MakeEnvelope 返回该视口内的所有项目。
CREATE OR REPLACE FUNCTION public.search_projects_area(
lngw double precision,
lats double precision,
lnge double precision,
latn double precision
) RETURNS SETOF project_locations LANGUAGE sql STABLE AS $ function $
SELECT
A.*
FROM
project_locations A
WHERE
st_intersects(
A.location :: geography,
ST_MakeEnvelope(lngw, lats, lnge, latn, 4326) :: geography
) $ function $
以下是我如何获取创建信封的坐标:
const bounds = this.map.getBounds();
const sw = this.map.getBounds().getSouthWest();
const ne = this.map.getBounds().getNorthEast();
const lngw = sw.lng();
const lats = sw.lat();
const lnge = ne.lng();
const latn = ne.lat();
问题在于,有时无法获取特定区域的项目,具体取决于我缩放或定位地图的位置。尽管在所有情况下,项目都在视口内。
好像ST_MakeEnvelope 方法没有根据地图视口创建正确的矩形。
我上面的代码正确吗?
【问题讨论】:
标签: postgresql google-maps google-maps-api-3 maps postgis