title: Calculate distance between two long/lat
body: <p>After researching a lot and not coming to a solution i have to ask. 
  How can I calculate the distance between two Long/Lat Points in Mysql? (efficient way?)</p>
  
  <p>I also found <a href="https://stackoverflow.com/questions/1006654/fastest-way-to-find-distance-between-two-lat-long-points">this</a> solution, but there I dont know which @lat @long is and i am not using Points because spring-data-jpa doesnt allow a Geometry Type (Except using MysqlSpatial dialect) </p>
  
  <p>In Java i am calculating like this: </p>
  
  <pre><code>private double getDistanceFromLatLonInKm(double lat1,double lon1,double lat2,double lon2) {
      int R = 6371; //Earth Radius
      double dLat = degreeToRadiant(lat2-lat1);
      double dLon = degreeToRadiant(lon2-lon1);
      double a =
              Math.sin(dLat/2) * Math.sin(dLat/2) +
                      Math.cos(degreeToRadiant(lat1)) * Math.cos(degreeToRadiant(lat2)) *
                              Math.sin(dLon/2) * Math.sin(dLon/2)
              ;
      double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
      return R * c; //Distance in km
  }
  </code></pre>
  
  <p>And my table/Entity contains one column for longitude and another for latitude. </p>
  
  <p>Another question, could there be a possibility to solve this with as said before with spring data jpa?</p>
  
  <p>I tried to translate the Java code to Mysql, but the Distances are to high.</p>
  
  <pre><code>SELECT name, (6371 * (
      2 * ATAN2(
                  SQRT(
                      SIN(RADIANS((48.3069400-latitude))/2) * SIN(RADIANS((48.3069400-latitude)/2)) +
                      COS(RADIANS(latitude)) * COS(RADIANS(48.3069400)) * SIN(RADIANS((48.3069400-longitude)/2)) *
                      SIN(RADIANS((48.3069400-longitude)/2))
                  ),SQRT(
                      1-(SIN(RADIANS((48.3069400-latitude))/2) * SIN(RADIANS((48.3069400-latitude)/2)) +
                      COS(RADIANS(latitude)) * COS(RADIANS(48.3069400)) * SIN(RADIANS((48.3069400-longitude)/2)) *
                      SIN(RADIANS((48.3069400-longitude)/2)))
                  )
              )
  )) as distance FROM event
  </code></pre>