这个字段类型是mysql5.7新增的功能,主要就是解决坐标存储和距离计算的常见问题

创建表:
create table `service` (
`id` bigint(20) not null auto_increment,
`name` varchar(128) not null default ”,
`content` varchar(128) not null default ”,
`tel` varchar(20) not null default ”,
`location` geometry not null,
primary key (`id`),
key `location` (`location`(32))
) engine=innodb auto_increment=1 default charset=utf8

插入坐标
insert into service (name,content,tel,location)values(“陶士涵”,’牛逼’,’18898989898′,st_geomfromtext(‘point(116.28828 40.053257)’));
读取坐标
select *,astext(location) from service;
查询距离
select name,content,tel, (st_distance (location,point(116.282459,40.047955) ) *111195) as distance from service order by distance;
判断距离
select name,content,tel,astext(location),floor(st_distance (location,point(116.282459,40.047955) ) *111195) as distance from service having distance < 1000 order by distance;