/*** @desc calculates distance according to latitude and longitude between two points * @param float $lat Latitude value * @param float $LNG Longitude value */function Getdistance ($lat 1, $lng 1, $ LAT2, $lng 2) { $earthRadius = 6367000;//approximate radius of Earth in meters/ * Convert these degrees to Rad Ians to work with the formula * * $lat 1 = ($lat 1 * PI ())/; $LNG 1 = ($lng 1 * PI ())/; $lat 2 = ($lat 2 * PI ())/; $LNG 2 = ($lng 2 * PI ())/; /* Using the haversine formula http://en.wikipedia.org/wiki/Haversine_formula Calculate the Distance * /$calcLongitude = $lng 2-$LNG 1; $calcLatitude = $lat 2-$lat 1; $stepOne = Pow (sin ($calcLatitude/2), 2) + cos ($lat 1) * cos ($lat 2) * POW (sin ($calcLongitude/2), 2); $STEPTWO = 2 * ASIN (MIN (1, sqrt ($stepOne))); $calculatedDistance = $earthRadius * $STEPTWO; Return round ($calculatedDistance); }