title: Calculating bearing between two CLLocation points in Swift
body: <p>I'm trying to calculate a bearing between two CLLocation points in swift-only code.  I've run into some difficulty and was assuming this is a pretty simple function.  Stack overflow didn't seem to have anything listed.</p>
  
  <pre><code>func d2r(degrees : Double) -&gt; Double {
      return degrees * M_PI / 180.0
  }
  
  func RadiansToDegrees(radians : Double) -&gt; Double {
      return radians * 180.0 / M_PI
  }
  
  
  func getBearing(fromLoc : CLLocation, toLoc : CLLocation) {
  
      let fLat = d2r(fromLoc.coordinate.latitude)
      let fLng = d2r(fromLoc.coordinate.longitude)
      let tLat = d2r(toLoc.coordinate.latitude)
      let tLng = d2r(toLoc.coordinate.longitude)
  
      var a = CGFloat(sin(fLng-tLng)*cos(tLat));
      var b = CGFloat(cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(fLng-tLng))
  
      return atan2(a,b)
  }
  </code></pre>
  
  <p>I'm getting an error with my atan2 call about lvalue cgfloat or something...</p>