够意思博客够意思博客够意思博客

MYSQL根据经纬度实现距离从近到远排序

MYSQL根据经纬度实现距离从近到远排序

-- 商户按经纬度距离排序
SELECT
	NAME,
	latitude,
	longitude,
	FLOOR(
		st_distance (
			ST_GeomFromText (
				CONCAT(
					'POINT(',
					longitude,
					' ',
					latitude,
					')'
				)
			),
			point (
				102.72925026604903,
				25.13330078526236
			)
		) * 111195
	) AS distance
FROM
	ch_shop
HAVING
	distance < 5000
ORDER BY
	distance;

查询语句

SELECT name,latitude,longitude,FLOOR(st_distance (ST_GeomFromText( CONCAT('POINT(',longitude,' ',latitude,')')),point(102.72925026604903,25.13330078526236) ) *111195) AS distance FROM ch_shop having distance < 5000 ORDER BY distance;

查询结果

MYSQL根据经纬度实现距离从近到远排序(图1)

本文为够意思原创文章,转载无需和我联系,但请注明来自够意思博客blog.go1s.cn:够意思博客 » MYSQL根据经纬度实现距离从近到远排序

加载中~