Advertisement
cdsatrian

geo distance diff

Mar 28th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.40 KB | None | 0 0
  1. DROP FUNCTION IF EXISTS GeoDistDiff;
  2.  
  3. DELIMITER |
  4. CREATE FUNCTION GeoDistDiff( type ENUM('miles', 'kilometers'), lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT ) RETURNS FLOAT
  5. BEGIN
  6.   RETURN ( IF(type = 'kilometers', 6371, 3959) * acos( cos( radians(lat2) ) * cos( radians( lat1 ) ) * cos( radians( lon1 ) - radians(lon2) ) + sin( radians(lat2) ) * sin( radians( lat1 ) ) ) );
  7. END;
  8. |
  9.  
  10. DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement