您好,欢迎访问一九零五行业门户网

MySQL的geometry类型处理经纬度距离的方法介绍

本篇文章给大家带来的内容是关于mysql的geometry类型处理经纬度距离的方法介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
建表
create table `map` (  `id` int(11) not null,  `address` varchar(255) not null default '',  `location` geometry not null,  primary key (`id`),  spatial key `idx_location` (`location`))
插入
insert into map (id, address, location) values (1, 'somewhere', st_geomfromtext('point(121.366961 31.190049)'));
注意必须使用 st_geomfromtext 函数,且 point() 里面是:经度+空格+纬度查询1. 查看经纬度select address, st_astext(location) as location from map;
2. 计算两点之间的距离select st_distance_sphere(point(121.590347, 31.388094),location) as distant from map;
算出来的结果,单位是米
注意现在point()里面经纬度之间是逗号分隔的3. 查询距离小于1000m的地点,并由远及近排序select id, address, st_distance_sphere(point(121.590347, 31.388094),location) as distant from map where st_distance_sphere(point(121.590347, 31.388094),location) < 1000 order by distant;
以上就是mysql的geometry类型处理经纬度距离的方法介绍的详细内容。
其它类似信息

推荐信息