Skip to content

Instantly share code, notes, and snippets.

View djordjevics1998's full-sized avatar

Стефан Ђорђевић (Stefan Đorđević) djordjevics1998

View GitHub Profile
@chessworld
chessworld / distance.sql
Created March 19, 2012 04:44
MySQL stored procedure for distance calculation
create function distance(lat1 real, lng1 real, lat2 real, lng2 real) returns real no sql
return ATAN2(SQRT(POW(COS(RADIANS(lat2)) * SIN(RADIANS(lng1 - lng2)), 2) +
POW(COS(RADIANS(lat1)) * SIN(RADIANS(lat2)) - SIN(RADIANS(lat1)) *
COS(RADIANS(lat2)) * COS(RADIANS(lng1 - lng2)), 2)),
(SIN(RADIANS(lat1)) * SIN(RADIANS(lat2)) + COS(RADIANS(lat1)) *
COS(RADIANS(lat2)) * COS(RADIANS(lng1 - lng2)))) * 6372.795;