方式1:st_distance_sphere
st_distance_sphere
函数返回以米为单位
SELECT*,st_distance_sphere (point ( longitudes, latitudes ),point ( 113.264435, 23.129163 )) AS juli
FROMzxh_distance
ORDER BYjuli ASC;
方式2:st_distance
st_distance
返回的度
st_distance 计算的结果单位是度,需要乘111195(地球半径6371000*PI/180)是将值转化为米。
SELECT*,st_distance (point ( longitudes, latitudes ),point ( 113.264435, 23.129163 )) AS juli
FROMzxh_distance
ORDER BYjuli ASC;
方式3 直接计算
SELECT*,ROUND(6378.138 * 2 * ASIN(SQRT(POW( SIN(( 23.129163 * PI()/ 180-latitudes * PI()/ 180 )/ 2 ), 2 )+ COS( 23.129163 * PI()/ 180 )* COS( latitudes * PI()/ 180 )* POW( SIN(( 113.264435 * PI()/ 180-longitudes * PI()/ 180 )/ 2 ), 2 )))* 1000 ) AS juli
FROMzxh_distance
ORDER BYjuli ASC
原文链接:https://blog.csdn.net/qq_39632561/article/details/119949634
st_distance_sphere原文:https://dev.mysql.com/doc/refman/8.0/en/spatial-convenience-functions.html
st_distance原文:https://dev.mysql.com/doc/refman/8.0/en/spatial-relation-functions-object-shapes.html#function_st-distance