php mysql compare long and lat, return ones under 10 miles

前端 未结 6 1681
借酒劲吻你
借酒劲吻你 2020-12-15 00:35

Hay i want to find the distance (in miles) between 2 locations using lat and long values, and check if they are within a 10 mile radius of each other.

When a user lo

6条回答
  •  暖寄归人
    2020-12-15 01:27

    I'm just going to leave this here:

    https://gist.github.com/899413

    it's an example on how to query within a square (BETWEEN) on integers and cut down the results with SQRT() to have the output return a round radius of results. (it also returns the distance in kilometer)

    to do this you need to convert all points, when inserting, to kilometers to lay them out on a flat map. (see php functions)

    the result is an incredible fast integer lookup - MUCH faster than doing all the calculations within the query like every single answer here states.

    (I built this exactly 10 years ago... seems like it's still the smartest solution with mysql)

提交回复
热议问题