Optimising a haversine formula SQL call in PHP

后端 未结 2 1820
面向向阳花
面向向阳花 2020-12-16 02:22

I\'m creating an MySQL call using PHP, I\'m calculating distance using the haversine forumula:

SELECT name, id,
   (6371 * acos(cos(radians(\' . $lat . \'))          


        
相关标签:
2条回答
  • 2020-12-16 02:51

    You're using the Spherical Law of Cosines formula, not the Haversine Formula (which is slightly slower).

    Doing the math in MySQL will probably be much faster, I advise you to read this question I asked a while back, as for speed optimizations you should definitely read the excellent Geo Proximity Search with MySQL paper, pay special attention to pages 8-14 and 19.

    0 讨论(0)
  • 2020-12-16 03:10

    For a super fast MySQL indexer, Check out Sphinx. It is extremely fast for finding what you need in your MySQL database, and does geo/distance calculations automatically.

    Tutorial: Geo/Spatial Search Using Sphinx Search and PHP

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