title: Geo Coordinates (Long,Lat) to Meters (x,y)
body: <p>I am working coordinates system as shown below:</p>
  
  <p><a href="https://i.stack.imgur.com/a7SlN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a7SlN.png" alt="enter image description here"></a></p>
  
  <p>x and y are in meters. I am interested in only positive x,y. I want to convert (x,y) to (lat,lon) and vise versa. </p>
  
  <p>I thought it is simple and I dont see a problem with my solutions below. But I am not getting very correct results. </p>
  
  <p><strong>My Solution:</strong></p>
  
  <p>As we see in the image below, I considered the Latitude and Longitude as angles of 2 circles:</p>
  
  <p><a href="https://i.stack.imgur.com/Sh97P.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Sh97P.jpg" alt="enter image description here"></a></p>
  
  <p><strong>1. (x,y) to (lat,lon)</strong></p>
  
  <p>I applied the Arc Length formula (<a href="https://formulas.tutorvista.com/math/angle-formulas.html" rel="nofollow noreferrer">here</a>), shown below, on both; x and y
  <a href="https://i.stack.imgur.com/0XcgD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0XcgD.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/z0p2E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z0p2E.png" alt="enter image description here"></a></p>
  
  <p>Hence, my functions are:</p>
  
  <pre><code>private static double calculateLat(float x) {
      int earthRadius = 6371000;
      return REF_LOC.getLatitude() + x*360/(2*PI*earthRadius);
  }
  
  private static double calculateLong(float y) {
      int earthRadius = 6371000;
      return REF_LOC.getLongitude() + y*360/(2*PI*earthRadius);
  }
  </code></pre>
  
  <p>REF_LOC is the reference Geo Location for which (x,y) are (0,0). It can be any point on earth.</p>
  
  <p><strong>2. (lat,lon) to (x,y)</strong></p>
  
  <p>For this I am simply using this:</p>
  
  <pre><code>int calculateX(double longitude){
          Location.distanceBetween(REF_LOC.getLatitude(), REF_LOC.getLongitude(),
                  REF_LOC.getLatitude(), lonDeg, results);
          return results[0];
  }
  
  int calculateY(double latitude){
          Location.distanceBetween(REF_LOC.getLatitude(), REF_LOC.getLongitude(),
                  latDeg, REF_LOC.getLongitude(), results);
          return results[0];
  }
  </code></pre>
  
  <p>But I am getting inconsistent results. First I use solution 1 and convert some value (x,y) to (lat,long). But when I use the same (lat,long) back to (x,y) using solution 2, I get about 2 meters difference in x and 10 meters in y. Can anyone help me identify the problem please?</p>