小编典典

用SQL计算2点之间的距离

sql

我必须计算2个点之间的距离,X和Y是第一个点的坐标,而axisX和axisY是第二个点的坐标。我唯一的线索是此SQL语句,但是此SQL不会返回我要查找的结果。那么,有谁能帮助我确定我在此声明中可能犯的任何错误?

string x = "SELECT TownName,Address,SUBSTRING(X, 1, 2) AS Xaxis, SUBSTRING(Y, 1, 2) AS Yaxis,Type,Availability,Price,Size,Bedrooms,Bathrooms,Contact,Screenshot1,Screenshot2,Screenshot3,Screenshot4 FROM House"+
                                    "WHERE (SQRT(POWER(X - "+axisX+" , 2) + POWER(Y - "+axisY+", 2)) <= 2000)";

阅读 45

收藏
2021-04-28

共1个答案

小编典典

SELECT <replace with your select>,

3963.0 * ACOS (
    sin(SUBSTRING(X, 1, 2)/57.2958) * sin(" + axisX + "/57.2958) + cos(SUBSTRING(X, 1, 2)/57.2958) * cos(" + axisX + "/57.2958) * cos(" + axisY + "/57.2958 - SUBSTRING(Y, 1, 2)/57.2958))
as distance
 FROM House
ORDER BY distance

我假设axisX和axisY是您的坐标。这使用距离计算技术,可以为您提供更准确的读数。

http://www.meridianworlddata.com/Distance-
Calculation.asp

希望这可以帮助。

2021-04-28