zoukankan      html  css  js  c++  java
  • mysql 下 计算 两点 经纬度 之间的距离 含具体sql语句

    /*传入的参数为  纬度 纬度 经度 ASC升序由近至远 DESC 降序 由远到近 */

    SELECT
        *,
        ROUND(
            6378.138 * 2 * ASIN(
                SQRT(
                    POW(
                        SIN(
                            (
                                40.0497810000 * PI() / 180 - lat * PI() / 180
                            ) / 2
                        ),
                        2
                    ) + COS(40.0497810000 * PI() / 180) * COS(lat * PI() / 180) * POW(
                        SIN(
                            (
                                116.3424590000 * PI() / 180 - lon * PI() / 180
                            ) / 2
                        ),
                        2
                    )
                )
            ) * 1000
        ) AS juli
    FROM
        customer
    ORDER BY
        juli ASC
    

      

    lat, lon为经纬度

    php代码

    //根据经纬度计算距离 其中A($lat1,$lng1)、B($lat2,$lng2)
    function getDistance($lat1,$lng1,$lat2,$lng2) {
        //地球半径
        $R = 6378137;
        //将角度转为狐度
        $radLat1 = deg2rad($lat1);
        $radLat2 = deg2rad($lat2);
        $radLng1 = deg2rad($lng1);
        $radLng2 = deg2rad($lng2);
        //结果
        $s = acos(cos($radLat1)*cos($radLat2)*cos($radLng1-$radLng2)+sin($radLat1)*sin($radLat2))*$R;
        //精度
        $s = round($s* 10000)/10000;
        return  round($s);
    }
  • 相关阅读:
    OS-lab4
    OS-lab3
    OS-lab2
    OS-lab1
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    HTTP_POST
    实习日志1(2020.7.27-2020.9.31)
    Web app ------ 从Servlet读取Json数据并显示,生成历史数据曲线图
  • 原文地址:https://www.cnblogs.com/ilys/p/9571065.html
Copyright © 2011-2022 走看看