Home >Backend Development >PHP Tutorial >Query nearby location information based on longitude and latitude
Now there is such a demand. I want to query the five locations nearby two kilometers in the data table based on the longitude and latitude of the current location. If the query result does not include five locations, I want to expand the nearby range until five locations are found. . I thought of two options:
The first option is to implement it completely using sql statements. If it is completely implemented using sql statements, I don’t know how to write this sql,
The second option is to query first, and then make a judgment based on the business results. If the 5 locations are not met, expand the nearby range and query in the database again until 5 locations are found.
I don’t know which of the two options is more efficient, please give me some advice. Grateful.