Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find "nearby" results?

Assuming you have the latitude and longitude of your user, and you want to find nearby... let's say restaurants, how do you query your relational DB? For something like "restaurants within a 25 mile radius"?

Would you just query for restaurants in a square with a long and lat greater than/less than the user's loc +/- 25 miles (converted to degrees I guess), and then filter out the "corners" in whatever language your using? Or can/should you do it directly in the SQL?

like image 519
mpen Avatar asked Dec 17 '22 23:12

mpen


1 Answers

Take a look at the spatial features available in oracle for instance - here is the wikipedia entry http://en.wikipedia.org/wiki/Spatial_query, and a link with examples from noaa https://www.ngdc.noaa.gov/wiki/index.php?title=Sample_Oracle_Spatial_Queries

like image 149
Jubal Avatar answered Mar 08 '23 00:03

Jubal