Building a carpooling app for my local community built on PHP and SQL. While I'm usually ofay with php coding, I'm stumped looking for the mathematical formula needed to list:
- Top 5 nearby users, ordered from closest to furthest given the long / lat of the primary user
- Limited to those within 500 meters of the primary users long / lat
The SQL database contains the long / lat of every online user that is updated at 5 minute intervals.
Have searched around, but think I may be looking for the wrong thing. Any guidance is greatly appreciated.
The following SQL query uses Spherical Law of Cosines to calculate the distance between a coordinate and coordinates in a table.
The query uses SQL Math functions
Using PDO instead of deprecated
mysql_
functions.You will require to modify the statement to suit . Also remove the echo in catch block after debugging.