mysql计算两个经纬度之间的距离_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.

第一个函数是计算平面坐标系下,两点的距离,就是

1edda0b372d241142c8279df6ae9441f.png

如果用于计算地球两点的距离,带入的参数是角度(0-360度),则计算的单位也是相差的角度,用此角度计算距离不准。纬度距离约111km每度,经度距离在赤道平面上是111km每度,随纬度的升高逐渐降低为0。

第二个函数是计算球面距离的公式,传入的参数是经纬度(经度-180~180,纬度-90~90),返回的值以m为单位的距离。

Returns the mimimum spherical distance between two points and/or multipoints on a sphere, in meters, or NULL if any

你可能感兴趣的:(mysql计算两个经纬度之间的距离_mysql计算两个经纬度之间的距离公式)