- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 MySQL 5.7 中,有一个名为 ST_Distance_Sphere
的函数,可用于查找半径内的点,例如:
CREATE TABLE `places` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(256) DEFAULT NULL,
`coordinates` point DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `places` ( `name`, `coordinates`)
VALUES ("Eiffel Tower", POINT(48.858271, 2.293795));
INSERT INTO `places` ( `name`, `coordinates`)
VALUES ("Pere Lachaise", POINT(48.861131, 2.394683));
INSERT INTO `places` ( `name`, `coordinates`)
VALUES ("Brooklyn", POINT(40.711089, -73.948391));
如果我们想查看距离巴黎市中心卢浮宫不到10公里的所有点,我们可以这样做:
SELECT name FROM places
WHERE ST_Distance_Sphere(coordinates, POINT(48.861105, 2.335337)) < 10000
但是 MariaDB 10.1+ 中不支持此类函数
如何在 MariaDB 中重新创建相同的函数或重新创建相同的查询。以下帖子展示了重新创建相同函数的一种方法 FUNCTION ST_Distance_Sphere does not exist in MariaDB ?
也许是这样的?
SELECT name FROM places
WHERE ST_Within(
coordinates, ST_Buffer(POINT(48.861105, 2.335337), 10000)
);
感谢任何帮助。
最佳答案
基于@adam78和@Rick James的建议我是这样解决的:
CREATE FUNCTION st_distance_sphere(pt1 POINT, pt2 POINT)
RETURNS double(10,2)
RETURN 6371000 * 2 * ASIN(
SQRT(
POWER(SIN((ST_Y(pt2) - ST_Y(pt1)) * pi()/180 / 2), 2) +
COS(ST_Y(pt1) * pi()/180 ) *
COS(ST_Y(pt2) * pi()/180) *
POWER(SIN((ST_X(pt2) - ST_X(pt1)) * pi()/180 / 2), 2)
)
)
关于mysql - MariaDB 没有 ST_Distance_Sphere 的等效函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59370894/
在尝试创建一个应用程序,其功能之一是搜索给定点附近的某些地方时,我遇到了以下错误: SequelizeDatabaseError: st_distance_sphere (geometry, geom
我正在尝试查询一个小表以查找表中输入坐标点 1 公里以内的所有记录。表中的每条记录都有一个带有相应点的“Lat”和“Long”列。我的查询是 var sql = `SELECT * FROM GeoT
我正在做一个 Python 项目,我有两个纬度/经度对,我想计算它们之间的距离。在其他项目中,我使用 ST_Distance_Sphere(a.loc_point, b.loc_point) 在 Po
这是我的代码: SELECT st_distance_sphere( POINT(8,51) , point(@lon, @lat)) as distance FROM places; 如果我执行它
在 MySQL 5.7 中,有一个名为 ST_Distance_Sphere 的函数,可用于查找半径内的点,例如: CREATE TABLE `places` ( `id` int(11) uns
使用 st_distance_sphere 时从 MySQL 给出的结果看起来真的很不稳定。 在用户表上运行此查询:(距离点9.45公里以内的用户列表) select *, st_distance_s
我的要求 是计算给定map 上两个位置 之间的距离使用 mysql .我在 mysql 中找到了一个函数命名为ST_Distance_Sphere它返回球体上两个位置和/或多个位置之间的最小球面距离(
我想获取我所在位置周围的所有位置,但函数 ST_Distance_Sphere 不起作用。 我的查询: select *, astext(location) as location from `loc
我有包含列 ID、名称、位置的表格区域。列位置是 POINT 类型,存储地点的(纬度、经度)。 我读到了一个在 MySQL 中使用点数据类型和 st_distance_sphere 查找最近地点的解决
我正在使用 PostgreSQL v9.1.11 和 PostGIS 2.1.0。我正在使用 st_distance_sphere 来计算各个点之间的距离,但得到的结果不正常。根据文档,该函数应返回提
我有一个 MySQL 查询: UPDATE `location` `l1` SET `l1`.`city_id` = ( SELECT `c1`
我是 Postgis 和空间方面的新手,我正在为非常简单的查询而苦苦挣扎。 我在 places 中有两条记录用于测试,其中列 addressLocation 是具有以下值的 POINT: (51.12
我有一个名为 place 的表: id | name | coordinates (longitude, latitude) 1 | London | -0.12574, 51.
我发现了这个Stack Overflow问题。 Distance in meters between two Spacial Points in MySQL query 我想为我的用例实现它,但出现此
我是一名优秀的程序员,十分优秀!