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;    

 

上一篇:按距离搜索邻近城市的一种实现


下一篇:JS 百度地图 地图线路描绘