当前位置:网站首页>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
查询后的结果:
边栏推荐
- [chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
- Film and television excerpts
- 【外刊】睡眠与减肥
- 悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
- Go condition variable
- Introduction to database system Chapter 1 short answer questions - how was the final exam?
- Socket socket c/s end process
- NC24325 [USACO 2012 Mar S]Flowerpot
- Jatpack------LiveData
- PHP wechat red packet grabbing algorithm
猜你喜欢
Commodity information management system (C language document version)
Oracle PL / SQL programming
Mathematical modeling -- graph and network models and methods (I)
开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...
Performance optimization - rigorous mode
Oracle-PL/SQL编程
kubernetes 使用主机名将 pod 分配在指定节点上
uniapp微信登录返显用户名和头像
[LeetCode] 数组中的第K个最大元素【215】
Niuke: Dragon and dungeon games
随机推荐
Jatpack------LiveData
uniapp微信登录返显用户名和头像
Leetcode circular linked list (fast and slow pointer) code line by line interpretation
杰理之直接触摸样机的顶针反应不正常【篇】
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
服务器响应状态码
go 4種單例模式
[leetcode] reverse the word III in the string [557]
PHP optimizes SQL queries in foreach
#include errors detected. Please update your includePath.
Go four singleton modes
任务和特权级保护
Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning
Wait to solve the zombie process
解决 excel 文件上传时更改选中的文件出现错误net::ERR_UPLOAD_FILE_CHANGED
《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...
The threshold value of fusing proportion cannot be changed with sentinel, and setting the slow call proportion has no effect
Jatpack------LiveData
Socket socket c/s end process