title: Calculating coordinates given a bearing and a distance
body: <p>I am having problems implementing the function described here <a href="http://williams.best.vwh.net/avform.htm#LL" rel="noreferrer">here</a>.</p>
  
  <p>This is my Java implementation:</p>
  
  <pre><code>private static double[] pointRadialDistance(double lat1, double lon1, 
          double radianBearing, double radialDistance) {
       double lat = Math.asin(Math.sin(lat1)*Math.cos(radialDistance)+Math.cos(lat1)
               *Math.sin(radialDistance)*Math.cos(radianBearing));
       double lon;
       if(Math.cos(lat) == 0) {  // Endpoint a pole
          lon=lon1;      
       }
       else {
          lon = ((lon1-Math.asin(Math.sin(radianBearing)*Math.sin(radialDistance)/Math.cos(lat))
                  +Math.PI) % (2*Math.PI)) - Math.PI;
       }
      return (new double[]{lat, lon});
  }
  </code></pre>
  
  <p>I convert the degree bearing to radians and convert the distance (km) into a radians distance before calling the function - so that's not the problem.</p>
  
  <p>However, when I input coordinates such as:
  lat = 49.25705;
  lon = -123.140259;
  with a bearing of 225 (south-west) and a distance of 1km</p>
  
  <p>I get this returned:
  lat: -1.0085434360125864 
  lon: -3.7595299668539504</p>
  
  <p>Its obviously not correct, can anyone see what I am doing wrong?</p>
  
  <p>Thanks</p>