Order table by proximity to specific latitude/longitude (using MySQL+PHP)

后端 未结 1 595
日久生厌
日久生厌 2021-02-08 14:09

MySQL (table)

id | url |    lat    |    lng
----------------------------------
1  |  x  | 44.339565 | -101.337891
----------------------------------
2  |  y  | 4         


        
1条回答
  •  心在旅途
    2021-02-08 14:33

    You may be interested in checking out the following presentation:

    • Geo/Spatial Search with MySQL1 by Alexander Rubin

    The author describes how you can use the Haversine Formula in MySQL to order by proximity and limit your searches to a defined range. He also describes how to avoid a full table scan for such queries, using traditional indexes on the latitude and longitude columns.


    1 PDF Version

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