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)'));查询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;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类型处理经纬度距离的方法介绍的详细内容,更多请关注小潘博客其它相关文章!