sql 坐标距离排序计算距离(转)

如果两个坐标的列是(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 AS BEGIN --距离(千米) 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 @Distance END

使用: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));

}

posted @ 2015-02-13 10:26  文艺流浪汉  阅读(3165)  评论(0编辑  收藏  举报