mysql 地理位置查詢

2021-10-07 10:47:27 字數 4058 閱讀 2696

mysql 官方指南為 glength(linestringfromwkb(linestring(point1, point2)))

首先建立位置表結構

create table `locationpoint` (

`id` int(11) not null,

`pt` point not null,

`province` varchar(20) not null,

`city` varchar(20) not null,

`longitude` double(10,3) not null,

`latitude` double(10,3) not null,

`geo_code` varchar(12) not null comment 'geohash編碼',

primary key (`id`)

) engine=innodb default charset=utf8;

插入字段 示例一部分資料

insert into `locationpoint` values ('1147', geomfromtext('point(117.17 31.52)'), '安徽省', '合肥', '117.170', '31.520', 'uxyrvrbpvpzr');

insert into `locationpoint` values ('1148', geomfromtext('point(117.02 30.31)'), '安徽省', '安慶', '117.020', '30.310', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1149', geomfromtext('point(117.21 32.56)'), '安徽省', '蚌埠', '117.210', '32.560', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1150', geomfromtext('point(115.47 33.52)'), '安徽省', '亳州', '115.470', '33.520', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1151', geomfromtext('point(117.52 31.36)'), '安徽省', '巢湖', '117.520', '31.360', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1152', geomfromtext('point(118.18 32.18)'), '安徽省', '滁州', '118.180', '32.180', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1153', geomfromtext('point(115.48 32.54)'), '安徽省', '阜陽', '115.480', '32.540', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1154', geomfromtext('point(117.28 30.39)'), '安徽省', '貴池', '117.280', '30.390', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1155', geomfromtext('point(116.47 33.57)'), '安徽省', '淮北', '116.470', '33.570', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1156', geomfromtext('point(116.58 32.37)'), '安徽省', '淮南', '116.580', '32.370', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1157', geomfromtext('point(118.18 29.43)'), '安徽省', '黃山', '118.180', '29.430', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1158', geomfromtext('point(115.21 33.15)'), '安徽省', '界首', '115.210', '33.150', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1159', geomfromtext('point(116.28 31.44)'), '安徽省', '六安', '116.280', '31.440', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1160', geomfromtext('point(118.28 31.43)'), '安徽省', '馬鞍山', '118.280', '31.430', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1161', geomfromtext('point(117.58 32.47)'), '安徽省', '明光', '117.580', '32.470', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1162', geomfromtext('point(116.58 33.38)'), '安徽省', '宿州', '116.580', '33.380', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1163', geomfromtext('point(118.59 32.41)'), '安徽省', '天長', '118.590', '32.410', 'zzzzzzzzzzzz');

insert into `locationpoint` values ('1164', geomfromtext('point(117.48 30.56)'), '安徽省', '銅陵', '117.480', '30.560', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1165', geomfromtext('point(118.22 31.19)'), '安徽省', '蕪湖', '118.220', '31.190', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1166', geomfromtext('point(118.44 30.57)'), '安徽省', '宣州', '118.440', '30.570', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1167', geomfromtext('point(119.18 26.05)'), '福建省', '福州', '119.180', '26.050', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1168', geomfromtext('point(119.31 25.58)'), '福建省', '長樂', '119.310', '25.580', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1169', geomfromtext('point(119.39 27.06)'), '福建省', '福安', '119.390', '27.060', 'bpbpbpbpbpbp');

insert into `locationpoint` values ('1170', geomfromtext('point(119.23 25.42)'), '福建省', '福清', '119.230', '25.420', 'bpbpbpbpb

sql 根據空間查詢

select id, point(longitude,latitude) as pt from locationpoint where 0.5 >= glength(linestringfromwkb(linestring(pt, point(113.4 ,34.46))))
根據位址獲取經緯度:

根據ip查詢地理位置

圍繞純真資料庫的一系列小工具 文件,文件 文件純真資料庫utf 8版本。轉換工具也以開源形式發布,用php實現 nali,名字取自中文 的拼音。nali包含一組命令列程式,其主要功能就是把一些網路工具的輸出的ip字串,附加上地理位置資訊 使用純真資料庫 例如218.65.137.1會變成218.65...

es之地理位置查詢

為了方便學習es的地理位置查詢,這裡準備了一些地理座標為測試資料,每一條資料都包含城市名稱和地理座標兩個字段。首先把下面的內容儲存到geo.json檔案中 然後建立乙個索引 put geo settings filter filter filter filter filter 4 查詢geo sha...

洋山港 地理位置

洋山港區位於浙江省嵊泗縣境內。由大洋山港口區和小洋山港口區組成。可供開發的深水岸線4900公尺,是上海國際航運中心的深水港區。位於嵊泗海域西部大洋山島的北岸。東北距縣城21.41海浬,西北距上海市蘆潮港18.9海浬。大洋山島海岸線總長16697公尺 其中基岩10214公尺 可利用岸線3200公尺,聖...