日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人文社科 > 生活经验 >内容正文

生活经验

mysql 附近3公里的_mysql搜寻附近N公里内数据的实例

發(fā)布時(shí)間:2023/11/27 生活经验 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 附近3公里的_mysql搜寻附近N公里内数据的实例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

根據(jù)圓周率和地球半徑系數(shù)以及搜尋點(diǎn)的經(jīng)緯度,搜尋數(shù)據(jù)表中與搜尋點(diǎn)之間的距離為N公里內(nèi)的數(shù)據(jù)。

1.創(chuàng)建測(cè)試表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;

2.插入測(cè)試數(shù)據(jù)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 |

+----+--------------+----------------+---------------+

3.搜尋1公里內(nèi)的數(shù)據(jù)

搜尋點(diǎn)坐標(biāo):時(shí)代廣場(chǎng) 113.323568, 23.146436

6370.996公里為地球的半徑

計(jì)算球面兩點(diǎn)坐標(biāo)距離公式C = sin(MLatA)sin(MLatB)cos(MLonA-MLonB) + cos(MLatA)cos(MLatB)

Distance = RArccos(C)*Pi180

根據(jù)計(jì)算公式得到查詢(xún)語(yǔ)句如下: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í)行查詢(xún):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ù)的實(shí)例相關(guān)內(nèi)容,更多相關(guān)知識(shí)請(qǐng)關(guān)注Gxl網(wǎng)。

相關(guān)推薦:

mysql 連接閃斷自動(dòng)重連的方法

php 實(shí)現(xiàn)HTML實(shí)體編號(hào)與非ASCII字符串相互轉(zhuǎn)換類(lèi)

php 根據(jù)自增id創(chuàng)建唯一編號(hào)類(lèi)

總結(jié)

以上是生活随笔為你收集整理的mysql 附近3公里的_mysql搜寻附近N公里内数据的实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。