当前位置: 移动技术网 > IT编程>开发语言>PHP > [MySQL] mysql地理位置服务geometry字段类型

[MySQL] mysql地理位置服务geometry字段类型

2019年09月04日  | 移动技术网IT编程  | 我要评论
这个字段类型是mysql5.7新增的功能,主要就是解决坐标存储和距离计算的常见问题 创建表:CREATE TABLE `service` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL DEFAULT ' ...

这个字段类型是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;

 

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网