insert:
假设数据表A中的geometry类型的字段是‘location’,则添加的语句是:
insert into A('id','name','location') value(null,'测试数据',ST_GeomFromText('POINT(104.066143 30.573095)'));
POINT函数里面的参数左边是经度,右边是纬度,改变值
(update)也是一样的用法。
select
获取坐标信息:
SELECT ASTEXT(location) AS location FROM A
计算两点之间的距离:
select ST_Distance_Sphere (POINT(104.079971, 30.554951),location) AS distant from A
(以上坐标是随便找的坐标,左边是经度右边是纬度,不要定位来轰炸我。。。)
距离筛选,比如5公里范围内的数据:
select id,name, ST_Distance_Sphere (POINT(104.079971, 30.554951),location) AS distant from A where ST_Distance_Sphere (POINT(104.079971, 30.554951),location) < 5000 ORDER BY distant
目前我的mysql版本是5.7.17( select @@version;可查自己的版本),越新的版本可以使用的函数更多,详情请参考:MYSQL官网