zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    JavaScript脚本学习
    PE文件结构 (转贴)
    Squid 代理服务器 编译源码 伪造HTTP_X_FORWARDED_FOR 请求头
    设置win2003远程桌面允许2个以上会话
    2003远程桌面声音问题
    AS3正则表达式
    Visual Studio技巧之打造拥有自己标识的代码模板
    如何重建sql数据库索引
    多线程系列(转)
    时间差
  • 原文地址:https://www.cnblogs.com/qiangshu/p/1763556.html
Copyright © 2011-2022 走看看