zoukankan      html  css  js  c++  java
  • Geohash-》通过经纬度计算两地距离的函数

     /**
         * 根据起点坐标和终点坐标测距离
         * @param  [array]   $from  [起点坐标(经纬度),例如:array(118.012951,36.810024)]
         * @param  [array]   $to    [终点坐标(经纬度)]
         * @param  [bool]    $km        是否以公里为单位 false:米 true:公里(千米)
         * @param  [int]     $decimal   精度 保留小数位数
         * @return [string]  距离数值
         */  
        function get_distance($from,$to,$km=true,$decimal=2){  
            sort($from);  
            sort($to);  
            $EARTH_RADIUS = 6370.996; // 地球半径系数  
              
            $distance = $EARTH_RADIUS*2*asin(sqrt(pow(sin( ($from[0]*pi()/180-$to[0]*pi()/180)/2),2)+cos($from[0]*pi()/180)*cos($to[0]*pi()/180)* pow(sin( ($from[1]*pi()/180-$to[1]*pi()/180)/2),2)))*1000;  
              
            if($km){  
                $distance = $distance / 1000;  
            }  
          
            return round($distance, $decimal);  
        } 

  • 相关阅读:
    ORM&MySQL
    Python的内存管理机制
    Docker
    MySQL数据库优化
    Django&Flask区别
    Nginx
    JWT
    云接入特别说明
    gogs私有代码库上传项目
    Authentication failed (rejected by the remote node), please check the Erlang cookie
  • 原文地址:https://www.cnblogs.com/peipeiyu/p/7902704.html
Copyright © 2011-2022 走看看