How to find "nearby" results?

Assuming you have the latitude and longitude of your user, and you want to find nearby ... let the restaurants say, how do you request your relational database? Something like "restaurants within a 25 mile radius?"

Could you just request restaurants on an area with a long and latin size larger / smaller than that of the user +/- 25 miles (converted to degrees, I think), and then filter out the β€œcorners” in any language using? Or can you / should do it directly in SQL?

+4
source share
5 answers

Look at the spatial functions available, for example, in oracle - here is a 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

+4
source

Found a really good guide here: http://code.google.com/apis/maps/articles/phpsqlsearch.html

Much simpler than many other explanations ...

+3
source

Use the SQL implementation of the Haversin formula

+2
source

Your β€œcircle” will already be quite deformed if you treat lat / long as a straight mesh at any considerable distance from the equator (for example, in New York, London or Moscow). Trimming corners from a square does not improve it.

+2
source

I know that you specifically mentioned relational databases, but I would repeat that you would at least take a look at a system that has a built-in implementation of spatial queries.

Personally, I found MongoDB pretty elegant: http://www.mongodb.org/display/DOCS/Geospatial+Indexing

+1
source

Source: https://habr.com/ru/post/1313591/


All Articles