Skip to content

Instantly share code, notes, and snippets.

@toshiaki-h
Forked from masuidrive/calc_distance.sql
Last active December 17, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshiaki-h/5574142 to your computer and use it in GitHub Desktop.
Save toshiaki-h/5574142 to your computer and use it in GitHub Desktop.
DROP FUNCTION calc_distance;
CREATE FUNCTION calc_distance(lat1 DOUBLE, lon1 DOUBLE, lat2 DOUBLE, lon2 DOUBLE) RETURNS double
RETURN (ACOS(SIN(lat1 * PI() / 180) * SIN(lat2 * PI() / 180) + COS(lat1 * PI() / 180) * COS(lat2 * PI() / 180) * COS((lon1 - lon2) * PI() / 180)) * 180 / PI()) * 111189.57696;
@toshiaki-h
Copy link
Author

remove delimiter.

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