title: Splitting an area on the globe given by 4 Latitude Longitude coordinates into an equidistant grid?
body: <p>So I'm working on a final project in Java language, this project has a server side (which is under my responsibility) and a GUI client (which is under someones else responsibility).</p>
  
  <p>As a server I constantly get GPS coordination (as latitude longitude) from android clients and I need to reply with their equivalent location on a pre-allocated grid.</p>
  
  <p>The grid is set by 4 LatLng coords sent to me by the GUI client and the amount of grid lines to be divided by. E.g. I get (35.000,35.000),(35.000,36.000),(36.000,36.000),(36.000,35.000) and 40x40.</p>
  
  <p>The current method I use is by calculating the distance in radian degrees for the latitude distance of the area and the longitude distance separately, and then I divide it by 40 (like in the example given), each quotient is my "click", a single unit of distance I use later on.</p>
  
  <p>When I receive a new coordinate I divide it by my "click" and do a Math.floor, the quotient of this operation is the location on the grid.
  But something is wrong, my calculation are apparently incorrect, as the GUI client disagrees with me (usually by 1 grid north/south and 1 grid west/east, he simply takes the map (e.g. google-map) and manipulates it as a picture simply splitting a rectangular area.
  What am I doing wrong? is there a better way to discretize the area given by this setup?</p>
  
  <p>Things I've already check: 1. This is not some sort of float underflow, I used BigDecimal and <a href="https://github.com/JavadocMD/simplelatlng" rel="nofollow">SimpleLatLng</a>.</p>
  
  <ol start="2">
  <li>The GUI client agrees with me on locations closer to the relative 0x0 grid block, so it's not the usual off-by-one mistake.</li>
  </ol>
  
  <p>EDIT: I've managed to work out most of the error, I still have some error which I don't know what part of the code can be responsible.</p>
  
  <p>EDIT 2: The problem seems to be solved, the issue was not getting the correct bearing in the first place and just assuming the grid was north bound, the correct code is attached:</p>