mysql根据经纬度函数 st_distance计算距离查找结果

Mysql 发表时间:2020-03-23 14:36:05 作者:梁子亮 浏览次数:883

mysql版本要求,5.6或以上

$shop_lng = 22.271620;
$shop_lat = 113.546830;
$order = 'distance ASC';
$field = "id,round(st_distance (point (ar_shop.long, ar_shop.lat),point(".$long.",".$lat.") ) / 0.0111,2) AS distance";
$res = Db::name('shop')->field($field)->order($order)->having("distance<5")->select();
print_dump($res);die;

注意,若point后不添加ar_shop.直接写poing((long,lat),.....则会报错。tp5.1

上一篇   php单例模式