1.建立测试表
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.插进去测试数据
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千米内的数据
征采点坐标:时期广场 113.323568, 23.146436
6370.996千米为地球的半径
盘算球面两点坐标间隔公式
C = sin(MLatA)sin(MLatB)cos(MLonA-MLonB) + cos(MLatA)cos(MLatB)
Distance = RArccos(C)*Pi180
依据盘算公式获得查询语句以下:
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;
实行查询:
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千米内数据的实例相干内容,更多相干学问请关注ki4网。
相干引荐:
mysql 衔接闪断自动重连的要领
php 完成HTML实体编号与非ASCII字符串互相转换类
php 依据自增id建立唯一编号类
以上就是mysql 征采四周N千米内数据的实例的细致内容,更多请关注ki4网别的相干文章!