-
-
Save piffall/537f2ad6d0eb8c2bdb96 to your computer and use it in GitHub Desktop.
This file contains 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
-- http://dossy.org/2011/09/mysql-geo-distance-code-and-samples/ | |
DELIMITER $$ | |
DROP FUNCTION IF EXISTS geodist $$ | |
CREATE FUNCTION geodist ( | |
src_lat DECIMAL(9,6), src_lon DECIMAL(9,6), | |
dst_lat DECIMAL(9,6), dst_lon DECIMAL(9,6) | |
) RETURNS DECIMAL(6,2) DETERMINISTIC | |
BEGIN | |
SET @dist := 3956 * 2 * ASIN(SQRT( | |
POWER(SIN((src_lat - ABS(dst_lat)) * PI()/180 / 2), 2) + | |
COS(src_lat * PI()/180) * | |
COS(ABS(dst_lat) * PI()/180) * | |
POWER(SIN((src_lon - dst_lon) * PI()/180 / 2), 2) | |
)); | |
RETURN @dist; | |
END $$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment