Created
January 26, 2017 17:57
-
-
Save tmbritton/0fc62002880549749ce75655b6fc5459 to your computer and use it in GitHub Desktop.
MySQL lat/long select by distance
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 field_geo_data_lat, field_geo_data_lon, SQRT( | |
POW(69.1 * (field_geo_data_lat - [30.2707]), 2) + | |
POW(69.1 * ([-97.7533] - field_geo_data_lon) * COS(latitude / 57.3), 2)) AS distance | |
FROM field_data_field_geo_data HAVING distance < 25 ORDER BY distance; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, this doesn't take into account the curvature of the Earth. So if you're guiding missiles, don't use this.