用sql计算2点之间的距离

时间:2011-05-24 02:35:56

标签: c# sql silverlight

我必须计算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)";

1 个答案:

答案 0 :(得分:5)

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

希望这有帮助。