Tools.php
public static function gpsDistance($lat1, $lon1, $lat2, $lon2)
    {
        $lat1 = deg2rad($lat1);
        $lon1 = deg2rad($lon1);
        $lat2 = deg2rad($lat2);
        $lon2 = deg2rad($lon2);

        $lonDelta = $lon2 - $lon1;
        $a = ((cos($lat2) * sin($lonDelta)) ** 2) + ((cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($lonDelta)) ** 2);
        $b = sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($lonDelta);

        return atan2(sqrt($a), $b) * 6371.0088;
    }
public static function gpsDistance($lat1, $lon1, $lat2, $lon2)
    {
        $lat1 = deg2rad($lat1);
        $lon1 = deg2rad($lon1);
        $lat2 = deg2rad($lat2);
        $lon2 = deg2rad($lon2);

        $lonDelta = $lon2 - $lon1;
        $a = ((cos($lat2) * sin($lonDelta)) ** 2) + ((cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($lonDelta)) ** 2);
        $b = sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($lonDelta);

        return atan2(sqrt($a), $b) * 6371.0088;
    }
Calculates distance in kilometers between two GPS coordinates

@param float $lat1 GPS latitude 1
@param float $lon1 GPS longitude 1
@param float $lat2 GPS latitude 2
@param float $lon2 GPS longitude 2

@return float Distance between points in kilometers
@static