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

相关推荐
FirstFrost --sy13 分钟前
MySQL复合查询
数据库·mysql
imuliuliang26 分钟前
MySQL的底层原理与架构
数据库·mysql·架构
尽兴-33 分钟前
Redis7 底层数据结构解析
数据结构·数据库·缓存·redis7
m0_7301151142 分钟前
自动化机器学习(AutoML)库TPOT使用指南
jvm·数据库·python
qq_410194291 小时前
SQL语句性能优化
数据库·sql·性能优化
小江的记录本1 小时前
【MyBatis-Plus】Spring Boot + MyBatis-Plus 进行各种数据库操作(附完整 CRUD 项目代码示例)
java·前端·数据库·spring boot·后端·sql·mybatis
wanhengidc1 小时前
《三国志异闻录》搬砖新游戏 云手机
运维·服务器·数据库·游戏·智能手机
2301_807367191 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
2301_795741792 小时前
构建一个基于命令行的待办事项应用
jvm·数据库·python
FITA阿泽要努力2 小时前
《实战SQL: GROUP BY》
数据库·sql