mysql计算两个经纬度之间的距离公式
#1.两点距离(1.4142135623730951) select st_distance(point(0,0),point(1,1)); select st_distance(point (120.10591, 30.30163),point(120.13026,30.25961)); mysql 5.6 添加 #2.两点球面距离(157249.0357231545m) select st_distance_sphere(point(0,0),point(1,1)); select st_distance_sphere(point (120.10591, 30.30163),point(120.13026,30.25961)); This function was added in MySQL 5.7.6.
第一个函数是计算平面坐标系下,两点的距离,就是
如果用于计算地球两点的距离,带入的参数是角度(0-360度),则计算的单位也是相差的角度,用此角度计算距离不准。纬度距离约111km每度,经度距离在赤道平面上是111km每度,随纬度的升高逐渐降低为0。
第二个函数是计算球面距离的公式,传入的参数是经纬度(经度-180~180,纬度-90~90),返回的值以m为单位的距离。
ST_Distance_Sphere(
g1
, g2
[, radius
])
Returns the mimimum spherical distance between two points and/or multipoints on a sphere, in meters, or NULL
if any geometry argument is NULL
or empty.
Calculations use a spherical earth and a configurable radius. The optional radius
argument should be given in meters. If omitted, the default radius is 6,370,986 meters. An ER_WRONG_ARGUMENTS
error occurs if the radius
argument is present but not positive.
The geometry arguments should consist of points that specify (longitude, latitude) coordinate values:
-
Longitude and latitude are the first and second coordinates of the point, respectively.
-
Both coordinates are in degrees.
-
Longitude values must be in the range (-180, 180]. Positive values are east of the prime meridian.
-
Latitude values must be in the range [-90, 90]. Positive values are north of the equator.
Supported argument combinations are (Point
, Point
), (Point
, MultiPoint
), and (MultiPoint
, Point
). An ER_GIS_UNSUPPORTED_ARGUMENT
error occurs for other combinations.
If any geometry argument is not a syntactically well-formed geometry byte string, an ER_GIS_INVALID_DATA
error occurs.
mysql> SET @pt1 = ST_GeomFromText('POINT(0 0)');
mysql> SET @pt2 = ST_GeomFromText('POINT(180 0)');
mysql> SELECT ST_Distance_Sphere(@pt1, @pt2);
+--------------------------------+
| ST_Distance_Sphere(@pt1, @pt2) |
+--------------------------------+
| 20015042.813723423 |
+--------------------------------+
This function was added in MySQL 5.7.6.
- linux(十)配置ssh免密登录实现
- 微信群也有群相册功能了,终于可以给手机相册腾出空间了!
- PHP5.3、PHP5.4安装ZendOptimizer
- linux(十一)之初始化文件
- C编译: 动态连接库 (.so文件)
- 腾讯叮当首都发布生态合作伙伴计划,全面开放AI能力
- Python火爆的背后的应用领域是数据挖掘、大数据和人工智能的应用吗?
- linux(九)之网络基础
- eclipse从数据库逆向生成Hibernate实体类
- C编译: 使用gdb调试
- linux(八)linux系统中查找文件二
- Java魔法堂:String.format详解
- Java基础12 类型转换与多态
- linux(七)之linux系统中查找文件
- MySQL 教程
- MySQL 安装
- MySQL 管理与配置
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- mysql order by
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- 查看MySQL 元数据
- MySQL 序列 AUTO_INCREMENT
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- MYSQL 函数大全
- MySQL Group By 实例讲解
- MySQL Max()函数实例讲解
- mysql count函数实例
- MYSQL UNION和UNION ALL实例
- MySQL IN 用法
- MySQL between and 实例讲解