当前位置:网站首页>MySQL查询附近的数据.并按距离进行排序.
MySQL查询附近的数据.并按距离进行排序.
2022-07-02 22:09:00 【会飞的哈士奇】
业务背景:
查看我附近的公共厕所, 查询的时候通过传入当前使用人的经度(lng)与纬度(lat), 与数据库里的厕所信息进行位置计算, 得出我距离每个厕所的距离(单位:公里), 并且按照距离的远近进行排序, 最近的显示在最上面
SELECT
t1.name,
t1.address,
t1.uid,
t1.code
CONVERT(ACOS(COS(${lat}*PI()/180 )*COS(t1.lat*PI()/180)*COS(${lng}*PI()/180-t1.lng*PI()/180)+SIN(${lat}*PI()/180 )*SIN(t1.lat*PI()/180))*6370996.81/1000, DECIMAL(10,2)) AS distance
FROM
toilet t1
WHERE
t1.is_delete = '0'
ORDER BY
distance ASC查询后的结果:

边栏推荐
- 【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler
- 电商系统微服务架构
- Mathematical modeling -- graph and network models and methods (I)
- uniapp微信登录返显用户名和头像
- 数据分析学习记录--用EXCEL完成简单的单因素方差分析
- [LeetCode] 存在重复元素【217】
- Solve the error of changing the selected file when uploading excel file. Net:: err_ UPLOAD_ FILE_ CHANGED
- PHP optimizes SQL queries in foreach
- Commodity information management system (C language document version)
- 【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
猜你喜欢

Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly

UE4 游戏架构 学习笔记

Radis:Linux上安装Redis(步骤)

Socket socket c/s end process
![[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)](/img/2b/f31b81cedf37ca187bcaa20dfe0b83.png)
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)

Niuke: Dragon and dungeon games

【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等

UE4 game architecture learning notes

杰理之、产线装配环节【篇】

Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
随机推荐
Jatpack------LiveData
Gas station [problem analysis - > problem conversion - > greed]
Struct, bit segment, enumeration, union
Storage unit conversion
E-commerce system microservice architecture
百度智能云-创建人脸识别应用
Using rendertext() to output multiple lines of text with rendertext() in R shiny
U++ 学习笔记 ----松弛
Notes on key vocabulary of the original English book biography of jobs (IX) [chapter seven]
杰理之、产线装配环节【篇】
[LeetCode] 数组中的第K个最大元素【215】
php实现根据输入的年龄查询出生日期符合的数据
[LeetCode] 多数元素【169】
kubernetes 使用主机名将 pod 分配在指定节点上
Baidu AI Cloud - create a face recognition application
Oracle PL / SQL programming
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
Array advanced improvement
数学建模——图与网络模型及方法(一)
任务和特权级保护