五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動(dòng)態(tài)

mysql 搜尋附近N公里內(nèi)數(shù)據(jù)的簡單實(shí)例

發(fā)布日期:2022-05-01 11:22 | 文章來源:gibhub

根據(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ì)算公式得到查詢語句如下:

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ù)的簡單實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持本站。

香港穩(wěn)定服務(wù)器

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對(duì)1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部