mysql 获取距离某点最近的数据

方式一

算法:st_distance (POINT ( latitude, longitude ),POINT ( 106.695823, 26.574557 )) * 111195

SELECT
	*,
	st_distance (POINT ( latitude, longitude ),POINT ( 106.695823, 26.574557 )) * 111195 AS distance 
FROM
	test_distance 
ORDER BY
	distance DESC

方式二

算法:6371 * ACOS( COS( RADIANS( latitude ) ) * COS( RADIANS(106.739439) ) * COS( RADIANS( longitude - 26.594800 ) ) + SIN( RADIANS( latitude ) ) * SIN( RADIANS( 106.739439) )
)

SELECT
	*,
	6371 * ACOS( COS( RADIANS( latitude ) ) * COS( RADIANS(106.739439) ) * COS( RADIANS( longitude - 26.594800 ) ) + SIN( RADIANS( latitude ) ) * SIN( RADIANS( 106.739439) ) 
	) AS distance 
FROM
	test_distance 
ORDER BY
	distance ASC;

你可能感兴趣的:(功能模块,mysql,笔记)