This is the sample code snippet for you. It's working well for me. Feel free to adapt with your own logic.


$lat1 = "10.5900627";
$lon1 = "77.1933317";

$lat2 = "10.6068507";
$lon2 = "77.117246";

function distance($lat1, $lon1, $lat2, $lon2, $unit) 
{
  if (($lat1 == $lat2) && ($lon1 == $lon2)) {
    return 0;
  }
  else {
    $theta = $lon1 - $lon2;
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    $unit = strtoupper($unit);

    if ($unit == "K") {
      return ($miles * 1.609344);
    } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
      return $miles;
    }
  }
}

if(distance($lat1, $lon1, $lat2, $lon2, "K") < 10)
{
  echo "True";
}
else
{
  echo "False";
}


If the result of 'K' is less than 10Km, then you will get the result as "True". Otherwise 'False' will return as result.
0
2023-06-29
PHP: Hypertext Preprocessor
0
0
2023-06-29
PHP: Hypertext Preprocessor
0
0

Contact Us

If you have any inquiries or feedback, please don't hesitate to reach out to us at [email protected]. We will respond to your request as soon as possible. Thank you very much for your interest!

Country profiles