功能ST_Distance_Sphere不存在MariaDB的

问题描述 投票:2回答:3

我想避开我的位置的所有位置,但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)
database mariadb latitude-longitude
3个回答
1
投票

我的回答对DBA.SE直接复制,


几乎令人难以置信,MariaDB lacks this ST_Distance_Sphere (MDEV-13467)

查找their support matrix here

而且它不只是要么,它也缺乏ST_GeoHash是MySQL有。


1
投票

对于那些谁仍然需要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

0
投票

我认为这是它ST_DISTANCE https://mariadb.com/kb/en/library/st_distance/

© www.soinside.com 2019 - 2024. All rights reserved.