【发布时间】:2023-02-10 07:55:57
【问题描述】:
我有 2 个表,1 个用于设施,1 个用于客户。两者都包含我们想要查询以获取客户在 1 英里设施内可用的经纬度。我们不想使用像 ST_Distance 这样的 postgres 函数。实现它的任何替代查询。
【问题讨论】:
-
只需在 sql 中转置 https://stackoverflow.com/a/11172685/8060017 给出的公式
-
谢谢 Edouard,我们使用 haversine 公式来计算以英里为单位的距离。
-
私人双距离(双 LatOne,双 LonOne,双 LatTwo,双 LonTwo){ LonOne = Math.toRadians(LonOne); LonTwo = Math.toRadians(LonTwo); LatOne = Math.toRadians(LatOne); LatTwo = Math.toRadians(LatTwo);双 deltaLon = LonTwo - LonOne;双 deltaLat = LatTwo - LatOne;双公式 = Math.pow(Math.sin(deltaLat / 2), 2)+ Math.cos(LatOne) * Math.cos(LatTwo)* Math.pow(Math.sin(deltaLon / 2),2);双 fOutput = 2 * Math.asin(Math.sqrt(公式));返回 (fOutput * 3956) ; }
标签: postgresql