最近做快递上门取件业务,当获取用户位置经纬度时,如何快递查询出离用户最近的站点位置,以便让离用户最近的快递小哥上门取件,我的方式是直接在sql语句中计算最近的点
SELECT id,code,name,city_name,address,
(6371 * acos(cos(radians(31.2433336586)) * cos(radians(latitude)) * cos(radians(longitude) - radians(121.4579772949)) + sin(radians(31.2433336586)) * sin(radians(latitude)))) AS distance
FROM bmz_site ORDER BY distance LIMIT 0,10;
/*北京大成39.8995965929,116.4919853210 上海宝地31.2433336586,121.4579772949*/
我们改变经纬度的值,可以获取离我们的经纬度最近的前十条数据