0

i'm building a website that contains a database of places, and in the MySQL database i have stored the latitude and longitude of a certain place. When loaded, I then calculate the distance between the user (user's location is aquired via HTML5 Geolocation) and the stored location using either the haversine formula or google maps api's DistanceMatrix.

What I want is to order the output from the closest to the farthest location. Is that possible using a mysql query, or i can only do it with javascript?

1 Answers1

0

In the SQL query, you can create a new column that uses your formula to calculate the distance between the user and specific location. Then you want to use the ORDER BY keyword and choose the distance column to sort by ASC (already default). I hope this helps!

Stephan Genyk
  • 177
  • 1
  • 6