Created
January 12, 2015 10:09
-
-
Save sethmclean/eaef874610024fddfe14 to your computer and use it in GitHub Desktop.
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
SET | |
@orig_latitude = 32.867073, | |
@orig_longitude = -96.769410, | |
@radius = 10 | |
; | |
SELECT * | |
FROM ( | |
SELECT | |
`geonameid`, `name`, | |
3956 * ACOS(COS(RADIANS(@orig_latitude)) * COS(RADIANS(`latitude`)) * COS(RADIANS(@orig_longitude) - RADIANS(`longitude`)) + SIN(RADIANS(@orig_latitude)) * SIN(RADIANS(`latitude`))) AS `distance` | |
FROM `geoname` | |
WHERE | |
`latitude` | |
BETWEEN @orig_latitude - (@radius / 69) | |
AND @orig_latitude + (@radius / 69) | |
AND `longitude` | |
BETWEEN @orig_longitude - (@radius / (69 * COS(RADIANS(@orig_latitude)))) | |
AND @orig_longitude + (@radius / (69* COS(RADIANS(@orig_latitude)))) | |
) r | |
WHERE `distance` < @radius | |
ORDER BY `distance` ASC | |
; |
Thank you very much, this is just took milliseconds to get the data.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks mate.