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

相关推荐
踢足球0929几秒前
寒假打卡:1-29
数据库
wniuniu_几秒前
日志内容和cephadm
数据库·ceph
Nandeska几秒前
11、MySQL主从复制的基本概念
数据库·mysql
蓝黑20202 分钟前
SQL的union和union all
数据库·sql
qq_192779876 分钟前
如何用FastAPI构建高性能的现代API
jvm·数据库·python
晚风_END9 分钟前
postgresql数据库|连接池中间件pgbouncer的部署和配置详解
数据库·后端·spring·postgresql·中间件·个人开发
panzer_maus11 分钟前
Redis介绍(10)-缓存
数据库·redis·缓存
鸽芷咕11 分钟前
告别 Oracle 迁移痛点:金仓数据库的技术赋能与落地实效
数据库·oracle·金仓数据库
老友@12 分钟前
Redis 脑裂(Split-Brain)
数据库·redis·缓存·脑裂
naruto_lnq13 分钟前
用户认证与授权:使用JWT保护你的API
jvm·数据库·python