title: Relative Position in PHP between 2 points (Lat/Long)
body: <p>I have a database of airports with Latitude and Longitude for each point.  I want to run a PHP script to find all airports that are nearby a given airport, with their distance and relative direction.</p>
  
  <p>I.e.  for Airport KLDJ (40-37-02.810N   074-14-40.539W)</p>
  
  <p><strong>Airport Nearby</strong><br>
  KJFK - John F Kennedy Airport (21.2 nm NE) (40-38-23.104N   073-46-44.132W)</p>
  
  <p>I have used code from <a href="http://www.movable-type.co.uk/scripts/latlong.html" rel="nofollow noreferrer">http://www.movable-type.co.uk/scripts/latlong.html</a> to find distance, and tried to use it to find bearing, which might not be right.</p>
  
  <pre><code>//BEARING RHUMB LINE
  $phi = log(tan($lat2/2+pi/4)/tan($lat1/2+pi/4));
  $distance['bearing'] = (rad2deg(atan2($theta, $phi)) +180) % 360;
  </code></pre>
  
  <p>I basically want to run all points through this script and find the distance, which I have already, but then the direction.  (i.e. N, S, W, E, NW, SW, NE, SE)</p>