Some times in application we need to calculate the distance between two points . Let us suppose we have latitude and longitude of two points and we want to calculate that how far these two points are . So we have a simple function to calculate this .

function calculatedistance($lat1, $lon1, $lat2, $lon2, $unit) 
{
	$s = $lon1 - $lon2;
	$distance = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($s));
	$distance = acos($distance);
	$distance = rad2deg($distance);
	$miles = $distance * 60 * 1.1515;
	$unit = strtoupper($unit);

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

Now we have a function

calculatedistance()

and we need 5 arguments .Latitude1 , longitude1, latitude2, longitude2 and the unit. So we can simply call this function as given below.

   echo distance(31.05, 76.72, 30.7500, 76.78, "M") . " Miles
   echo distance(31.05, 76.72, 30.7500, 76.78, "K") . " Kilometers
   echo distance(31.05, 76.72, 30.7500, 76.78, "N") . " Nautical Miles
http://codingbin.com/wp-content/uploads/2015/11/PHP_Logo.pnghttp://codingbin.com/wp-content/uploads/2015/11/PHP_Logo-150x150.pngdevidphpdistance,phpSome times in application we need to calculate the distance between two points . Let us suppose we have latitude and longitude of two points and we want to calculate that how far these two points are . So we have a simple function to calculate this . Now we...coding, php, wordpress, yii, cakephp, and  jquery

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request