You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
440 B

  1. CREATE OR REPLACE FUNCTION `get_bearing`(
  2. lon1 DOUBLE,
  3. lat1 DOUBLE,
  4. lon2 DOUBLE,
  5. lat2 DOUBLE
  6. ) RETURNS double
  7. BEGIN
  8. SET @rlat1 = deg2rad(lat1);
  9. SET @rlat2 = deg2rad(lat2);
  10. SET @rlon1 = deg2rad(lon1);
  11. SET @rlon2 = deg2rad(lon2);
  12. SET @dlon = deg2rad(lon2 - lon1);
  13. SET @b = atan2(sin(@dlon) * cos(@rlat2), cos(@rlat1) * sin(@rlat2) - sin(@rlat1) * cos(@rlat2) * cos(@dlon));
  14. SET @bd = rad2deg(@b);
  15. RETURN MOD(@bd + 360, 360);
  16. END;