zoukankan      html  css  js  c++  java
  • tp5 根据经纬度计算门店距离 可排序

    $branchInfo=Db::name('Branch')->where('b_id','250')->find();
            $map['p.cate_id']=array('eq',5);
            $map['b.lng']=array('neq','');
            $map['b.lat']=array('neq','');
            $map['b.b_id']=array('neq',250);
            $branchGoodsList=Db::name('BranchStock')->alias('s')->field("s.s_id,s.s_stock,p.p_name,p.p_code,p.p_size,p.p_color,b.*,(6378.138 * 2 * asin(sqrt(pow(sin((lat * pi() / 180 - ".$branchInfo['lat']." * pi() / 180) / 2),2) + cos(lat * pi() / 180) * cos(".$branchInfo['lat']." * pi() / 180) * pow(sin((lng * pi() / 180 - ".$branchInfo['lng']." * pi() / 180) / 2),2))) * 1000) as distance")->join('think_products p','s.g_id=p.p_id','LEFT')->join('think_branch b','s.b_id=b.b_id','LEFT')->group('s.b_id')->where($map)->order('distance')->select();
            foreach($branchGoodsList as $k=>$v){
                $branchGoodsList[$k]['distance']=round($v['distance']/1000,2).'Km';
            }

    利用mysql 计算两点间具体  用百度地图接口计算距离太慢了  还有次数限制 因此改装了sql

  • 相关阅读:
    树状数组基础
    Color the ball HDU1556
    敌兵布阵 HDU1166
    线段树基础
    T9 HDU1298
    7-6 Bandwidth UVA140
    测试方法:
    测试过程:
    爬天极网美女图片缩略图:
    爬天极网美女预览图版一:
  • 原文地址:https://www.cnblogs.com/houdj/p/7988215.html
Copyright © 2011-2022 走看看