我想避开我的位置的所有位置,但ST_Distance_Sphere
不能正常工作的功能。
我的查询:
select *, astext(location) as location from `locations`
where ST_Distance_Sphere(location, POINT(35.905069591297, 49.765869174153)) < 1000
错误:
SQLSTATE[42000]: Syntax error or access violation:
1305 FUNCTION app.ST_Distance_Sphere does not exist (SQL:
select *, astext(location) as location from `locations`
where ST_Distance_Sphere(location, POINT(35.905069591297, 49.765869174153)) < 1000)
我的回答对DBA.SE直接复制,
几乎令人难以置信,MariaDB lacks this ST_Distance_Sphere
(MDEV-13467)。
而且它不只是要么,它也缺乏ST_GeoHash
是MySQL有。
对于那些谁仍然需要MariaDB的功能,您可以根据公式创建函数
CREATE FUNCTION `st_distance_sphere`(`pt1` POINT, `pt2` POINT) RETURNS
decimal(10,2)
BEGIN
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) ));
END
我认为这是它ST_DISTANCE
https://mariadb.com/kb/en/library/st_distance/