title: How to calculate distance between two latitude and longitude points?
body: <p>First of all while registering the futsal my system ask for location and saves latitude and longitude of that futsal in database.
  And when user visits my system, it ask for user's location and saves latitude and longitude in session.</p>
  
  <p>with the help of these futsal and user's latitude and location i want to calculate the distance between them in KM and show in the landing page.</p>
  
  <p>I have tried</p>
  
  <pre><code>$lat = $request-&gt;session()-&gt;get("latitude");
  $long = $request-&gt;session()-&gt;get("longitude");
  $data['futsals'] = DB::table("users")
              -&gt;where('is_futsal',1)
              -&gt;select("*",
              DB::raw("6371  * acos(cos(radians(".$lat."))
              * cos(radians(users.latitude))
              * cos(radians(users.longitude) - radians(".$long."))
              + sin(radians(".$lat."))
              * sin(radians(users.latitude))) AS distance"))
              -&gt;get();
  </code></pre>
  
  <p>It gives me distance but when ever i want to show the distance between user's and futsal the distance varies. I registered the futsal and login as a user from same place. which means the distance between them should be 0 but sometimes it gives me 0 also it gives me 1.9 km or 3.5 KM </p>