FUNCTION ST_Distance_Sphere does not exist in MariaDB

后端 未结 4 1059
-上瘾入骨i
-上瘾入骨i 2021-02-13 13:13

I want get all locations around my location but the function ST_Distance_Sphere does not work.

My query:

select *, astext(location) as locat         


        
相关标签:
4条回答
  • 2021-02-13 13:51

    A direct copy of my answer on DBA.SE,


    Almost unbelievably, MariaDB lacks this ST_Distance_Sphere (MDEV-13467).

    Find their support matrix here.

    And it's not just that either, it also lacks ST_GeoHash that MySQL has.

    0 讨论(0)
  • 2021-02-13 14:05

    I think that's it ST_DISTANCE https://mariadb.com/kb/en/library/st_distance/

    0 讨论(0)
  • 2021-02-13 14:11

    For those who still need the function in MariaDB, you can create the function based on the formula

        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 讨论(0)
  • 2021-02-13 14:13

    http://mysql.rjweb.org/doc.php/find_nearest_in_mysql#gcdistdeg

    That blog discusses multiple ways of "finding nearest" on the globe in MySQL/MariaDB. As part of that discussion, I developed that Stored Function.

    0 讨论(0)
提交回复
热议问题