I have a table which has a POINT
column containing the latitude and longitude of various locations.
I then also have a users location from geo-location in the browser.
What I need to be able to do is find all records from the table where the POINT
value in the is within a 10 km radius (or X km radius), ordered by distance with the closest first.
My table has a SPATIAL
index on the POINT
column.
The query below actually worked for me :
where: $user_lat and $user_lng is browser's lat and lng, $radius = 10, table name is parkings
I'm currently working on a project where I'm calculating distances between multiple locations. I'm using the following query for selecting object_id's which are within a given radius.
I can't explain the ACOS formula itself because I got it from research.
This is in kilometers.
May be this help for you, https://ru.scribd.com/presentation/2569355/Geo-Distance-Search-with-MySQL
For Django I use this
It search all users in squar 20km.