您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MySQL怎么计算两坐标距离并排序

2024/6/24 3:56:51发布26次查看
环境
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 distancefrom locationpointorder by distance;
查询结果
推荐:《mysql教程》
以上就是mysql怎么计算两坐标距离并排序的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product