title: Is my function correct to calculate distance between two latitude and longitude?
body: <p>i am woking in mysql.</p>
  
  <p>I want to make a function which returns distance between two coordinates.</p>
  
  <p>I want to get this distance in miles. </p>
  
  <p>this is my code:-</p>
  
  <pre><code>DROP FUNCTION `checkDistance`//
  
  CREATE DEFINER=`root`@`localhost` FUNCTION `checkDistance`(
  
  lat1 DOUBLE(18,15),
  
  lon1 DOUBLE(18,15),
  
  lat2 DOUBLE(18,15),
  
  lon2 DOUBLE(18,15)
  
  ) RETURNS double(18,15)
  
  DETERMINISTIC
  
  BEGIN
  
                  DECLARE delta_lat DOUBLE(18,15);
  
                  DECLARE delta_lon DOUBLE(18,15);
  
                  DECLARE temp1 DOUBLE(18,15);
  
                  DECLARE EARTH_RADIUS DOUBLE(18,15);
  
                  DECLARE distance DOUBLE(18,15);
  
                  SET lat1 = RADIANS(lat1);
  
                  SET lon1 = RADIANS(lon1);
  
                  SET lat2 = RADIANS(lat2);
  
                  SET lon2 = RADIANS(lon2);
  
                  SET delta_lat = lat2 - lat1;
  
                  SET delta_lon = lon2 - lon1;
  
                  SET temp1 = POW(SIN(delta_lat/2.0),2) + COS(lat1) * COS(lat2) * 
  
  POW(SIN(delta_lon/2.0),2);
  
                  SET EARTH_RADIUS = 3956.0;
  
                  SET distance = EARTH_RADIUS * 2 * ATAN2(SQRT(temp1),SQRT(1-temp1));
  
                  RETURN distance;
  
      END
  </code></pre>
  
  <p>whenever i provide these argument for testing :-</p>
  
  <p>lat1=26.860524000000000 lon1= 75.762005000000000</p>
  
  <p>lat2= 26.860084000000000  lon2=75.761745000000000</p>
  
  <p>then this output is generated:-
  0.008681244150493</p>
  
  <p>but when i provide above argument some other formulas then i get another results like this:-
  miles = 0.034364904109861 </p>
  
  <p>please tell me which one is correct ?
  I have searched so many times on net, and there are so many formula to calculate this distance. please check my above code and suggest me if there are some issues. I want very accurate result.</p>
  
  <p>Thank you in advance. You are welcome to post your suggestions.</p>