zoukankan      html  css  js  c++  java
  • thinkphp根据经纬度计算距离

                $field = 'ACOS(SIN(('.$addr["lat"].' * 3.1415) / 180 ) *SIN((a.lat * 3.1415) / 180 ) +COS(('.$addr["lat"].' * 3.1415) / 180 )
                    * COS((a.lat * 3.1415) / 180 ) *COS(('.$addr["lng"].' * 3.1415) / 180 - (a.lng * 3.1415) / 180 ) ) * 6380 as distance';
                $dot=Db::name('dot')
                    ->alias('a')
                    ->field($field.",dot_store_name,dot_door_photo,id,business_status,service_distance,xysm")
                    ->where($where)
                    ->having( "distance<=service_distance")
                    ->order("distance asc")
    //                ->page($page,$limit)
                    ->select();
    thinkphp 5.1 
     mysql 5.7版本以上
     https://dev.mysql.com/doc/refman/5.7/en/spatial-convenience-functions.html  
     
     
    $lists = appcarsmodelWash::fieldRaw("round(st_distance_sphere(point(".$data["longitude"].",".$data["latitude"]."),point(`longitude`,`latitude`))) distance ")
    ->where("status",1)
    ->orderRaw($order .",is_recommend desc")
    ->paginate();
     
    原生sql
    select shop.* 
    from
    (
    select * ,round(st_distance_sphere(point(120.012484,30.298926),point(`longitude`,`latitude`))) dis
     from test111.store 
    having dis < 5000
     order by dis limit 100000 ) shop
    group by shop.item_id
    order by dis
    limit 10
  • 相关阅读:
    如何禁用事件的浮升(div的子元素的点击事件会触发父元素的点击事件)
    如何用Ajax加载服务器的图片
    MyBaits一对一的查询方法
    WEB编程中获取src目录下的文件(没有src目录)
    Vs code背景图
    JS正则表达式
    宏任务和微任务:setTimeout和Promise执行顺序
    MySql操作(一)
    Js 运行机制和Event Loop
    浅拷贝与深拷贝
  • 原文地址:https://www.cnblogs.com/zlf2000/p/12930372.html
Copyright © 2011-2022 走看看