/**
     * 根据起点坐标和终点坐标测距离
     * @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);  
    }

Geohash-》通过经纬度计算两地距离的函数的更多相关文章

  1. 【微信开发】微信小程序通过经纬度计算两地距离php代码实现

    需求: 要求做个根据用户当前位置获取周围商家地址,并且按照由近到远排序, 方法一: 代码层实现 封装方法: /** * @desc 根据两点间的经纬度计算距离 * @param float $lat ...

  2. js根据经纬度计算两点距离

    js版-胡老师 google.maps.LatLng.prototype.distanceFrom = function(latlng) {    var lat = [this.lat(), lat ...

  3. geolocation获取当前位置显示及计算两地距离

    获取当前经纬度 利用HTML5(以及基于JavaScript的地理定位API),可以很容易地在页面中访问位置信息,下面代码,就可以简单的获取当前位置信息: <!DOCTYPE html> ...

  4. IOS根据两个经纬度计算相距距离

    //第一种苹果自带的 CLLocation *orig=[[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self double ...

  5. .NET资料之-根据两点经纬度计算直线距离

    最近做东西碰到要根据两点经纬度计算之间的直线距离,就网上找了查了下资料.因为这类接触的比较少,就直接找现成的代码了,没怎么研究.代码如下,作为记录. private const double EART ...

  6. mySQL函数根据经纬度计算两点距离

    DROP FUNCTION IF EXISTS func_calcDistance ; CREATE FUNCTION func_calcDistance( origLng ,), -- 目的地经度 ...

  7. mySQL函数根据经纬度计算两点距离 复制代码

    http://www.cnblogs.com/lujiulong/p/6185041.html https://my.oschina.net/u/2273085/blog/505172?p={{pag ...

  8. mysql根据经纬度求两地距离

    #1.两点距离(1.4142135623730951) ,),point(,)); select st_distance(point (120.10591, 30.30163),point(120.1 ...

  9. tp5 根据经纬度计算门店距离 可排序

    $branchInfo=Db::name('Branch')->where('b_id','250')->find(); $map['p.cate_id']=array('eq',5); ...

随机推荐

  1. Linux入门命令解释(1)

    第一章Linux安装及服务控制 1.  uname -r              //查看linux版本号 2.cat  /proc/cupinfo      //查看CPU信息 3.cat  /p ...

  2. JAVA入门[1]--安装JDK

    1.下载JDK并安装 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...

  3. C# Lock、Monitor避免死锁

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. 配置nginx支持path_info模式

    简介:我们用thinkphp,CodeIgniter框架的时候,地址基本都是IP/index.php/group_controller?***的模式,通过index.php入口访问php文件 这种模式 ...

  5. 【JMeter】选项-函数助手对话框应用举例

    String date="${__javaScript((new Date()).getFullYear()+'-'+((new Date()).getMonth()+1)+'-'+(new ...

  6. LeetCode #1 TwoSum

    Description Given an array of integers, return indices of the two numbers such that they add up to a ...

  7. python变量字符拼接

    cpu = instances['vcpus_current'] cpu1 = str(cpu) + '核' memory = instances['memory_current'] / 1024 m ...

  8. Python Web框架

    本节对Python Web框架学习 一.MTVModel: 存放所有数据库相关文件Template:模板文件,存放html文件View: 业务处理,即函数文件 二.MVCmodel: 存放数据库相关文 ...

  9. JAVA中的集合与排序

    一:常见的集合类 Collection接口  和   Map接口 Collection ①:collection是最常见的集合的上级接口. ②:继承自collection的常用接口有List,Set, ...

  10. Ryz的鬼题

    蚂蚁(ant)[题目描述]  小 R 种了一棵苹果树,这棵树上有 n 个节点(标号从 0 到 n-1),有 n-1 条树枝连接这  n 个节点,这 n 个节点相互连通.每条树枝的长度为 1.  苹果树 ...