sql 座標距離排序計算距離

來源:互聯網
上載者:User

標籤:

如果兩個座標的列是(x1,y1)、(x2,y2),那麼他們之間的距離:
SQRT((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2))

sql排序

SELECT * FROM m_store   

ORDER BY   

SQRT((121.517759-`longitude`)*(121.517759-`longitude`)+(31.178469-`latitude`)*(31.178469-`latitude`))  

PHP計算距離

/**
*求兩個已知經緯度之間的距離,單位為米
*@param lng1,lng2 經度
*@param lat1,lat2 緯度
*@return float 距離,單位米
*@author www.Alixixi.com
**/
function getdistance($lng1,$lat1,$lng2,$lat2){
//將角度轉為狐度
$radLat1=deg2rad($lat1);//deg2rad()函數將角度轉換為弧度
$radLat2=deg2rad($lat2);
$radLng1=deg2rad($lng1);
$radLng2=deg2rad($lng2);
$a=$radLat1-$radLat2;
$b=$radLng1-$radLng2;
$s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137*1000;
return $s;
}

echo getdistance(121.477551,31.270338, 118.782347,32.072796)."米";

計算地球上兩個座標點(經度,緯度)之間距離sql函數

go --計算地球上兩個座標點(經度,緯度)之間距離sql函數--lordbaby--整理:www.aspbc.com CREATE FUNCTION [dbo].[fnGetDistance](@LatBegin REAL, @LngBegin REAL, @LatEnd REAL, @LngEnd REAL) RETURNS FLOAT ASBEGIN --距離(千米) DECLARE @Distance REAL DECLARE @EARTH_RADIUS REAL SET @EARTH_RADIUS = 6378.137 DECLARE @RadLatBegin REAL,@RadLatEnd REAL,@RadLatDiff REAL,@RadLngDiff REAL SET @RadLatBegin = @LatBegin *PI()/180.0 SET @RadLatEnd = @LatEnd *PI()/180.0 SET @RadLatDiff = @RadLatBegin - @RadLatEnd SET @RadLngDiff = @LngBegin *PI()/180.0 - @LngEnd *PI()/180.0 SET @Distance = 2 *ASIN(SQRT(POWER(SIN(@RadLatDiff/2), 2)+COS(@RadLatBegin)*COS(@RadLatEnd)*POWER(SIN(@RadLngDiff/2), 2))) SET @Distance = @Distance * @EARTH_RADIUS --SET @Distance = Round(@Distance * 10000) / 10000 RETURN @DistanceEND

使用:SELECT FROM 商家表名 WHEREdbo.fnGetDistance(121.4625,31.220937,longitude,latitude) < 5

C#計算兩點GPS座標距離

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> /// <summary>
///計算兩點GPS座標的距離
/// </summary>
/// <param name="n1">第一點的緯度座標</param>
/// <param name="e1">第一點的經度座標</param>
/// <param name="n2">第二點的緯度座標</param>
/// <param name="e2">第二點的經度座標</param>
/// <returns></returns>
public static double Distance(double n1, double e1, double n2, double e2)
{
double jl_jd = 102834.74258026089786013677476285;
double jl_wd = 111712.69150641055729984301412873;
double b = Math.Abs((e1 - e2) * jl_jd);
double a = Math.Abs((n1 - n2) * jl_wd);
return Math.Sqrt((a * a + b * b));

}

sql 座標距離排序計算距離(轉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.