title: Calculate distance in (x, y) between two GPS-Points
body: <p>I'm looking for a smooth way to calculate the distance between two GPS Points, so I get the result like: "You have to go x meters up and y meters to the left - so I can work with a 2d-coordinate system, where I have my position as (0,0) and the other positions is showing the distance in (x, y) in meters from my position.</p>
  
  <p>My idea was to calculate the distance between the points using the haversine formula. (This returns my hypotenuse)</p>
  
  <p>In addition to that, I'm calculating the bearing between this two points. This is my alpha.</p>
  
  <p>With this two values, I wanted to use basic trigonometry functions to resolve my problem.</p>
  
  <p>So I tried to calculate:<code>catheti_1 = sin(alpha) * hypotenuse, catheti_2 = cos(alpha) * hypotenuse</code>.</p>
  
  <p>Maybe I'm doing something wrong, but my results are useless at the moment.</p>
  
  <p>So my question is: How can I calculate the distance in x and y direction between two GPS points? </p>
  
  <p>I'm calculating alpha in the following procedure:</p>
  
  <pre><code>public static double bearingTo(GPSBean point1, GPSBean point2) {
      double lat1 = Math.toRadians(point1.latitude);
      double lat2 = Math.toRadians(point2.latitude);
      double lon1 = Math.toRadians(point1.longitude);
      double lon2 = Math.toRadians(point2.longitude);
  
      double deltaLong = lon2 - lon1;
  
      double y = Math.sin(deltaLong) * Math.cos(lat2);
      double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
              * Math.cos(lat2) * Math.cos(deltaLong);
      double bearing = Math.atan2(y, x);
  
      return (Math.toDegrees(bearing) + 360) % 360;
  }
  </code></pre>