Hello Everyone, today I am here to guide you "How to calcuate distance between 2 place with the help of zip code in Php".
$point and $point are two places, you can pass these values into total_distance() function
$radius is earth radius in miles
$distance return the calculated distance between 2 points.
The below code helps you to find the distance between 2 place.
function total_distance($point1, $point2)
{
$radius = 3958; // radius
$deg_per_radius = 57.29578; // degrees
$distance = ($radius * pi() * sqrt(
($point1['lat'] - $point2['lat'])
* ($point1['lat'] - $point2['lat'])
+ cos($point1['lat'] / $deg_per_rad)
* cos($point2['lat'] / $deg_per_rad)
* ($point1['long'] - $point2['long'])
* ($point1['long'] - $point2['long'])
) / 180);
return $distance; // Returned using the units used for $radius.
}
0 Comment(s)