Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- Meters: 6371000, Miles: 3959000
DELIMITER $$
DROP FUNCTION IF EXISTS `DISTANCE_BETWEEN` $$
CREATE FUNCTION DISTANCE_BETWEEN (
lat1 float(10,6), lon1 float(10,6),
lat2 float(10,6), lon2 float(10,6)
) RETURNS DOUBLE DETERMINISTIC
BEGIN
return ACOS(SIN(lat1*PI()/180)*SIN(lat2*PI()/180)
+ COS(lat1*PI()/180)*COS(lat2*PI()/180)
* COS(lon2*PI()/180-lon1*PI()/180))
* 6371000;
END $$
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.