Created
May 25, 2016 11:19
-
-
Save codyogden/bd667b27c99f35e6926ebe28e912b5d2 to your computer and use it in GitHub Desktop.
A hacked together query for finding nearest locations in a database. :oldlat & :oldlng are the center point, :dist is number of miles from center point.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT *, ( 3959 * acos( cos( radians( :oldlat ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( :oldlng ) ) + sin( radians(:oldlat) ) * sin( radians( latitude ) ) ) ) AS distance FROM agency HAVING distance < :dist ORDER BY distance LIMIT :numb | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment