您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
环境
MySQL5.6
https://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions-object-shapes.html#function_st-distance
表结构及数据
DROP TABLE IF EXISTS `locationpoint`;
CREATE TABLE `locationpoint`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`province` varchar(20) NOT NULL,
`city` varchar(20) NOT NULL,
`longitude` double(10, 3) NOT NULL,
`latitude` double(10, 3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1156
DEFAULT CHARSET = utf8;INSERT INTO `locationpoint`
VALUES (1, '山东', '济南', 116.938477, 36.597889),
(2, '河北', '石家庄', 114.477539, 38.030786),
(3, '浙江', '杭州', 120.058594, 30.334954),
(4, '河南', '郑州', 113.629, 34.744),
(5, '安徽省', '合肥', 117.170, 31.520);查询方式
(以内蒙古自治区呼和浩特市为计算中心)
SELECT id,
city,
longitude,
latitude,
round(
(
st_distance(
point(longitude, latitude),
point(111.621094, 40.913513)
) / 0.0111
) * 1000
)
AS distance
FROM locationpoint
ORDER BY distance;查询结果

以上就是MySQL怎么计算两坐标距离并排序的详细内容,更多请关注亿速云其它相关文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。