#1.2点之间的距离(1.4142135623730951 ) selectst _ distance point (0,0 ),point (1,1 ) ); selectst _ distance (点(120.10591,30.30163 ),点(120.13026,30.25961 );
添加mysql 5.6
#2.两点球面距离(157249.0357231545m ) selectST_distance_sphere ) point(0,point ) 1,1 ) ); selectst _ distance _ sphere (点(120.10591,30.30163 ),点) 120.13026,30.25961 );
thisfunctionwasaddedinmysql5.7. 6。
第一个函数通过计算平面坐标系中两点的距离,如下所示
用于计算地球两点之间的距离,如果传入的参数为角度(0-360度),则计算单位也是不同的角度,用该角度计算距离不准确。 纬度距离约为111km/度,经度距离在赤道平面上为111km/度,随着纬度的增加逐渐降低到0。
第二个函数是计算球面距离的表达式,传递的参数是纬度和经度(经度- 180到180,纬度- 90到90 ),返回的值是m个单位的距离。
returnsthemimumsphericaldistancebetweentwopointsand/ormultipointsonasphere,in meters,ornullifanygeometryargumentisnulon
calculationsuseasphericalearthandaconfigurableradius.theoptionalradiusargumentshouldbegiveninmeters.if omitted,thedefaultional 986 meters.aner _ wrong _ argumentserroroccursiftheradiusargumentispresentbutnotpositive。
thegeometryargumentsshouldconsistofpointsthatspecify (longitude,latitude ) coordinate values:
longitudeandlatitudearethefirstandsecondcoordinatesofthepoint,respectively。
Both coordinates are in degrees。
longitudevaluesmustbeintherange (-180,180 ).positivevaluesareeastoftheprimemeridian。
latitudevaluesmustbeintherange [-90,90 ].positivevaluesarenorthoftheequator。
supportedargumentcombinationsare (点,点),) Point,多点),and ) MultiPoint,Point ).aner _ GIS _ u unsuint
ifanygeometryargumentisnotasyntacticallywell-formedgeometrybytestring,aner _ GIS _ invalid _ dataerroroccurs。
MySQL set @ pt1=ST _ geomfromtext (' point (0) );
MySQL set @ pt2=ST _ geomfromtext (' point (180 ) );
mysqlselectst _ distance _ sphere (@ pt1,@pt2;
-------------请参阅
|ST_distance_sphere(@pt1,@pt2 ) |
-------------请参阅
| 20015042.813723423 |
-------------请参阅
thisfunctionwasaddedinmysql5.7. 6。