For the distance calculation

A UDF (user defined function) to calculate distance between two zip codes as follow:
首先获取zip地址对应的经纬度值,从zip表中可以得到。
string  sqlSel  =   " select latitud,longitud from ziptable where zip_cd =  "   +  zip;
using  (SqlDataReader dr  =  SqlHelper.ExecuteReader(strCon, CommandType.Text, sqlSel))
{
    
if  (dr.Read())
    {
        latitud 
=  Convert.ToDouble(dr[ 0 ]);     // 得到zip地址的经度值
        longitud  =  Convert.ToDouble(dr[ 1 ]);   // 得到zip地址的纬度值
    }
}

计算任意两个zip之间的距离:
其中,参数latitud,longitud为其中一个zip的经纬度;lat,lon为另一个zip的经纬度。然后计算两个zip之间的距离。

private  double  GetDistance( double  latitud,  double  longitud,  double  lat,  double  lon)
{
    distance 
=
    Math.
Round ( 3959   *  Math. Atan (Math. Sqrt ( 1   -  ((Math. Sin (latitud  /   57.3 *  Math. Sin (lat  /   57.3 +
    Math.
Cos (latitud  /   57.3 *  Math. Cos (lat  /   57.3 *  Math. Cos (lon  /   57.3   -  longitud  /   57.3 ))  *  (Math. Sin (latitud  /   57.3
    
*  Math. Sin (lat  /   57.3 +  Math. Cos (latitud  /   57.3 *  Math. Cos (lat  /   57.3 *  Math. Cos (lon  /   57.3   -  longitud  /   57.3 )))) 
    
/  (Math. Sin (latitud  /   57.3 *  Math. Sin (lat  /   57.3 +  Math. Cos (latitud  /   57.3 *  Math. Cos (lat  /   57.3 *  
    Math.
Cos (lon  /   57.3   -  longitud  /   57.3 ))),  2 );
    
return  distance;
}

 

转载于:https://www.cnblogs.com/qiangshu/archive/2010/06/23/1763556.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值