新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
MySQL如何計算兩個坐標(biāo)的距離
環(huán)境
尚義網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)從2013年開始到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
MySQL5.6
https://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions-object-shapes.html#function_st-distance
表結(jié)構(gòu)及數(shù)據(jù)
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);
查詢方式
(以內(nèi)蒙古自治區(qū)呼和浩特市為計算中心)
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;
查詢結(jié)果
以上就是MySQL怎么計算兩坐標(biāo)距離并排序的詳細內(nèi)容,更多請關(guān)注創(chuàng)新互聯(lián)其它相關(guān)文章!
當(dāng)前標(biāo)題:MySQL如何計算兩個坐標(biāo)的距離
轉(zhuǎn)載來于:http://www.dlmjj.cn/article/igdhji.html