Skip to content

Instantly share code, notes, and snippets.

@AustinW
Last active December 14, 2015 19:49
Show Gist options
  • Save AustinW/5139274 to your computer and use it in GitHub Desktop.
Save AustinW/5139274 to your computer and use it in GitHub Desktop.
Geo searching
CREATE DEFINER=`root`@`localhost` FUNCTION `geo_distance_miles`(in_lat decimal(10,6), in_lon decimal(10,6), latitude decimal(10,6), longitude decimal(10,6)) RETURNS decimal(10,3)
DETERMINISTIC
RETURN
(
(
ACOS(
SIN(in_lat * PI() / 180) * SIN(latitude * PI() / 180) + COS(in_lat * PI() / 180) * COS(latitude * PI() / 180) * COS((in_lon - longitude) * PI() / 180)
) * 180 / PI()
) * 60 * 1.1515
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment