Advertisement
Bartosz_Popielarczyk

Untitled

Jul 26th, 2022
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (float)getHeadingForDirectionFromCoordinate:(CLLocationCoordinate2D)fromLoc toCoordinate:(CLLocationCoordinate2D)toLoc
  2. {
  3.     float fLat = degreesToRadians(fromLoc.latitude);
  4.     float fLng = degreesToRadians(fromLoc.longitude);
  5.     float tLat = degreesToRadians(toLoc.latitude);
  6.     float tLng = degreesToRadians(toLoc.longitude);
  7.    
  8.     float degree = radiansToDegrees(atan2(sin(tLng-fLng)*cos(tLat), cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(tLng-fLng)));
  9.    
  10.     if (degree >= -180 && degree < 180)
  11.     {
  12.         return degree;
  13.     }
  14.     else if (degree >= 180 && degree < 360){
  15.         return degree - 360;
  16.     }
  17.     else {
  18.         return degree + 360;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement