mysql 计算两个坐标距离

方式一:st_distance_sphere 计算结果单位米

sql 复制代码
SELECT *,
st_distance_sphere(point(lng,lat),point(lng,lat)) as distance
FROM table 

mysql 版本5.7 以上

方式二:st_distance 计算结果单位是度

sql 复制代码
SELECT *,
(st_distance(point(lng,lat),point(lng4,lat))*111195/1000 ) as distance
FROM table 

st_distance 计算的结果单位是度,需要乘111195(地球半径6371000*PI/180)是将值转化为米

mysql 版本5.6 以上

测试结果

st_distance_sphere 最准确

st_distance 结果都相差有点大。(单位都是米)

在线经纬度距离计算

1.http://www.atoolbox.net/Tool.php?Id=1001

2.https://www.lddgo.net/convert/distance

3.https://tool.box3.cn/lbs.html

相关推荐
Super 含8 小时前
Android 启动优化(五):线程、GC 与 IO 为什么会拖慢启动?
java·服务器·数据库
ltl8 小时前
向量检索引擎选型:决策树、RAG 回链与开放问题
数据库
坚持学习前端日记9 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
灯澜忆梦9 小时前
【MySQL17】进阶篇 | InnoDB引擎
数据库·mysql
anxiao_m9 小时前
2026制造业云桌面选型攻略,不同生产场景适配方案汇总
大数据·网络·数据库
许彰午9 小时前
# 数据库配拦截器,不用改BPMN
数据库
lv__pf10 小时前
redis【msb 2026金三银四redis上】
数据库·redis·缓存
布莱克60511 小时前
理解数据库聚簇索引:原理、优势与适用场景
数据库·mysql
Nturmoils11 小时前
只面对一张表:KingbaseES 超表如何简化海量时序数据管理
数据库