php mysql 根据经纬度排序

  $lat = trim($_POST['lat']);
        $lng = trim($_POST['lng']);
        $distance = "
        ROUND(
        6378.138 * 2 * ASIN(
            SQRT(
                POW(
                    SIN(
                        (
                            '$lat' * PI() / 180 - lat * PI() / 180
                        ) / 2
                    ),
                    2
                ) + COS(40.0497810000 * PI() / 180) * COS(lat * PI() / 180) * POW(
                    SIN(
                        (
                            '$lng' * PI() / 180 - lng * PI() / 180
                        ) / 2
                    ),
                    2
                )
            )
        ) * 1000 )  AS distance ";
        // 内容
        $sql = <<<doc
select id,title as shop_name,create_at,master_title,lng,lat,reg_address,province,city,area,address,start_at,end_at,phone,business_name,business_phone,pics,club_id,{$distance}
from jiazhen_shop_info as jsi
where 1=1 order by distance ASC,id desc
doc;    

猜你喜欢

转载自www.cnblogs.com/-mrl/p/11975922.html