Created
August 11, 2018 06:10
-
-
Save ralexandr/6db8a50ca6c0d1ba2a1bdf11a84f789b to your computer and use it in GitHub Desktop.
GET_DISTANCE SQL FUNCTION
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
CREATE FUNCTION `getDistance`(fromLat INT, fromLong INT, toLat INT, toLong INT) RETURNS float unsigned | |
READS SQL DATA | |
DETERMINISTIC | |
BEGIN DECLARE distance FLOAT DEFAULT 0; SET distance = ( 3959 * acos( cos( radians(fromLat) ) * cos( radians( toLat ) ) * cos( radians( fromLong ) - radians(toLong) ) + sin( radians(fromLat) ) * sin( radians( toLat ) ) ) ); RETURN distance; END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment