1 var req = new 2 { 3 //经度 4 Longitude = 1, 5 //纬度 6 Latitude = 1, 7 //跳过条数 8 offset = 1, 9 //显示条数 10 limit = 1, 11 //条件范围 每增加1搜索范围差不多增加110km 12 scope = 10, 13 }; 14 15 string sql = $@"select * from store where 1=1 "; 16 sql = sql + $@"and longitude > ({req.Longitude}-{ req.scope}) 17 and longitude < ({req.Longitude}+{ req.scope}) 18 and latitude > ({req.Latitude}-{ req.scope}) 19 and latitude< ({req.Latitude}+{ req.scope}) 20 order by ACOS(SIN(({req.Latitude} * 3.1415) / 180 ) *SIN((latitude * 3.1415) / 180 ) +COS(({req.Latitude} * 3.1415) / 180 ) * 21 COS((latitude * 3.1415) / 180 ) *COS(({req.Longitude}* 3.1415) / 180 - (longitude * 3.1415) / 180 ) ) * 6380 "; 22 sql = sql + ($@" limit { req.offset},{ req.limit}");
mysql 经纬度范围查询排序优化
Wesley13
2021-10-11
1180 0 0
点赞
收藏
评论区
加载中...