0
点赞
收藏
分享

微信扫一扫

Mysql 根据经纬度计算距离

王传学 2022-05-06 阅读 148
sql



方式1:st_distance_sphere

SELECT
	*,st_distance_sphere (
	point ( longitudes, latitudes ),
	point ( 113.264435, 23.129163 )) AS juli 
FROM
	zxh_distance 
ORDER BY
	juli ASC;

在这里插入图片描述





方式2:st_distance

SELECT
	*,st_distance (
	point ( longitudes, latitudes ),
	point ( 113.264435, 23.129163 )) AS juli 
FROM
	zxh_distance 
ORDER BY
	juli 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 
FROM
	zxh_distance 
ORDER BY
	juli 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

举报

相关推荐

0 条评论