Home  >  Article  >  Backend Development  >  Query nearby location information based on longitude and latitude

Query nearby location information based on longitude and latitude

WBOY
WBOYOriginal
2016-10-22 00:00:211678browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn