Skip to content

Instantly share code, notes, and snippets.

@tmbritton
Created January 26, 2017 17:57
Show Gist options
  • Save tmbritton/0fc62002880549749ce75655b6fc5459 to your computer and use it in GitHub Desktop.
Save tmbritton/0fc62002880549749ce75655b6fc5459 to your computer and use it in GitHub Desktop.
MySQL lat/long select by distance
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;
@tmbritton
Copy link
Author

Note, this doesn't take into account the curvature of the Earth. So if you're guiding missiles, don't use this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment