Skip to content

Instantly share code, notes, and snippets.

@ralexandr
Created August 11, 2018 06:10
Show Gist options
  • Save ralexandr/6db8a50ca6c0d1ba2a1bdf11a84f789b to your computer and use it in GitHub Desktop.
Save ralexandr/6db8a50ca6c0d1ba2a1bdf11a84f789b to your computer and use it in GitHub Desktop.
GET_DISTANCE SQL FUNCTION
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