D
D
Dima Petrov2020-10-01 22:07:59
Geolocation
Dima Petrov, 2020-10-01 22:07:59

MariaDB st_distance_sphere?

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)));


MariaDB [shlagsher]> SELECT st_distance_sphere(ST_GeomFromText('POINT(55.743571 37.621438)', 4326),
ST_GeomFromText('POINT(55.744235 37.624855)')) r;
+--------+
| r      |
+--------+
| 384.43 |
+--------+
1 row in set (0.00 sec)


and mysql 8 (5.7 also returns 384.43 ) returns the correct answer to the same query
226

Tell me how to fix the function? or how to get the distance correctly.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-10-02
@freeExec

383.75396597- distance on a spheroid
384.42757677- distance on a sphere

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question