nearest location using php 1

nearest location using php

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

Here is what the above code is Doing:
1. The SELECT statement is selecting the id and (distance) columns from the markers table.
2. The (distance) column is a calculation that uses the Haversine formula to calculate the distance between two points on a sphere.
3. The HAVING clause is filtering the results to only show the markers that are within a radius of 25 miles to the center of -122, 37.
4. The ORDER BY clause is sorting the results by distance.
5. The LIMIT clause is limiting the number of results to 20.

Similar Posts