It is not difficult if you have lat / long data, and if someone gives you the big circle distance formula in mySQL format.
@maggie gave a good link. How to efficiently find nearby locations near this place
Indexing strategy. Keep in mind that one minute of latitude (1/60 degree) is one nautical mile or 1.1515 miles (approximately) worldwide. Therefore, index your latitude column and search in this way. (If you are in that part of the world that uses a kilometer, you can convert, sorry for the answer βOld-British Empire Centerβ, but they determined the nautical mile.)
WHERE mylat BETWEEN column.lat-(myradius*1.1515) AND column.lat+(myradius*1.1515) AND (the big distance formula) <= myradius
This will give you both decent indexing of the database and fairly accurate distance circles.
One additional clarification: you can also index longitude. The problem is that the distance between the earth is not directly related to longitude. At the equator, this is one nautical mile per minute, but it is becoming smaller, and the poles have features. So you can add another term for your WHERE. It gives the correct results, but not as selective as latitude indexing. But it still helps index the search, especially if you have a lot of rows to sift. So you get:
WHERE mylat BETWEEN column.lat-(myradius*1.1515) AND column.lat+(myradius*1.1515) AND mylon BETWEEN column.lon-(myradius*1.1515) AND column.lon+(myradius*1.1515) AND (the big distance formula) < myradius
source share