本文主要給大家介紹MySQL 搜索附近數(shù)據(jù)實例解析,希望可以給大家補充和更新些知識,如有其它問題需要了解的可以持續(xù)在創(chuàng)新互聯(lián)行業(yè)資訊里面關(guān)注我的更新文章的。
創(chuàng)新互聯(lián)主營薩嘎網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP開發(fā)公司,薩嘎h5微信小程序定制開發(fā)搭建,薩嘎網(wǎng)站營銷推廣歡迎薩嘎等地區(qū)企業(yè)咨詢
CREATE TABLE `location` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `longitude` decimal(13,10) NOT NULL, `latitude` decimal(13,10) NOT NULL, PRIMARY KEY (`id`), KEY `long_lat_index` (`longitude`,`latitude`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into location(name,longitude,latitude) values ('廣州東站',113.332264,23.156206), ('林和西',113.330611,23.147234), ('天平架',113.328095,23.165376);mysql> select * from `location`; +----+--------------+----------------+---------------+| id | name | longitude | latitude | +----+--------------+----------------+---------------+| 1 | 廣州東站 | 113.3322640000 | 23.1562060000 | | 2 | 林和西 | 113.3306110000 | 23.1472340000 || 3 | 天平架 | 113.3280950000 | 23.1653760000 | +----+--------------+----------------+---------------+
搜尋點坐標:時代廣場 113.323568, 23.146436
6370.996公里為地球的半徑
計算球面兩點坐標距離公式
C = sin(MLatA)sin(MLatB)cos(MLonA-MLonB) + cos(MLatA)cos(MLatB)
Distance = RArccos(C)*Pi180
根據(jù)計算公式得到查詢語句如下:
select * from `location` where ( acos(sin(([#latitude#]*3.1415)/180) * sin((latitude*3.1415)/180) + cos(([#latitude#]*3.1415)/180) * cos((latitude*3.1415)/180) * cos(([#longitude#]*3.1415)/180 - (longitude*3.1415)/180))*6370.996)<=1;
執(zhí)行查詢:
mysql> select * from `location` where ( -> acos( -> sin((23.146436*3.1415)/180) * sin((latitude*3.1415)/180) + -> cos((23.146436*3.1415)/180) * cos((latitude*3.1415)/180) * cos((113.323568*3.1415)/180 - (longitude*3.1415)/180) -> )*6370.996 -> )<=1; +----+-----------+----------------+---------------+| id | name | longitude | latitude | +----+-----------+----------------+---------------+| 2 | 林和西 | 113.3306110000 | 23.1472340000 | +----+-----------+----------------+---------------+
本文講解了mysql 搜尋附近N公里內(nèi)數(shù)據(jù)的實例相關(guān)內(nèi)容,更多相關(guān)知識請關(guān)注創(chuàng)新互聯(lián)。
相關(guān)推薦:
mysql 連接閃斷自動重連的方法
php 實現(xiàn)HTML實體編號與非ASCII字符串相互轉(zhuǎn)換類
php 根據(jù)自增id創(chuàng)建唯一編號類
以上就是mysql 搜索附近數(shù)據(jù)實例解析詳細內(nèi)容,更多請關(guān)注創(chuàng)新互聯(lián)其它相關(guān)文章!
名稱欄目:mysql搜索附近數(shù)據(jù)實例解析
URL鏈接:http://jinyejixie.com/article30/ipioso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、手機網(wǎng)站建設(shè)、App開發(fā)、網(wǎng)站收錄、App設(shè)計、網(wǎng)站設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)