Source Code : Finding the distance between two points

PHP Is Open Source Programming Language You Can Download and use It, You required xampp server and wamp server . You download From xampp server from https://www.apachefriends.org/download.html. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://php.net/. Click Here or search from google with Libraries Name you get jar file related it and also http://php.net/ is a official site

Finding the distance between two points

 
<?php
function sphere_distance($lat1, $lon1, $lat2, $lon2, $radius = 6378.135) {
    $rad = doubleval(M_PI/180.0);
    
    $lat1 = doubleval($lat1) * $rad;
    $lon1 = doubleval($lon1) * $rad; 
    $lat2 = doubleval($lat2) * $rad;
    $lon2 = doubleval($lon2) * $rad;
    
    $theta = $lon2 - $lon1;
    $dist = acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($theta));
    if ($dist < 0) { $dist += M_PI; }

    return $dist = $dist * $radius;
}

$lat1 = 40.;
$lon1 = -50.;

$lat2 = 37;
$lon2 = -122;

$dist = sphere_distance($lat1, $lon1, $lat2, $lon2);
printf("%.2f
", $dist * 0.621);
?>
  
  

Thank with us