src/Helper/HaversineSphericalDistance.php
public static function calculate(
        float $firstLatitude,
        float $firstLongitude,
        float $secondLatitude,
        float $secondLongitude,
        int $digits = 0,
        int $earthRadius = self::EARTH_RADIUS_IN_KM
    ): float {
        $oneRad = ((2 * M_PI) / 360);

        return \round(
            \sqrt(
                (($oneRad * ($firstLatitude - $secondLatitude) * $earthRadius) ** 2)
                + (($oneRad * ($firstLongitude - $secondLongitude) * $earthRadius
                    * \cos($oneRad * ($firstLatitude + $secondLatitude) * .5)) ** 2)
            ),
            $digits
        );
    }
public static function calculate(
        float $firstLatitude,
        float $firstLongitude,
        float $secondLatitude,
        float $secondLongitude,
        int $digits = 0,
        int $earthRadius = self::EARTH_RADIUS_IN_KM
    ): float {
        $oneRad = ((2 * M_PI) / 360);

        return \round(
            \sqrt(
                (($oneRad * ($firstLatitude - $secondLatitude) * $earthRadius) ** 2)
                + (($oneRad * ($firstLongitude - $secondLongitude) * $earthRadius
                    * \cos($oneRad * ($firstLatitude + $secondLatitude) * .5)) ** 2)
            ),
            $digits
        );
    }
public static function calculate ( float $ firstLatitude , float $ firstLongitude , float $ secondLatitude , float $ secondLongitude , int $ digits = 0 , int $ earthRadius = self :: EARTH_RADIUS_IN_KM ) : float { $ oneRad = ( ( 2 * M_PI ) / 360 ) ; return \ round ( \ sqrt ( ( ( $ oneRad * ( $ firstLatitude - $ secondLatitude ) * $ earthRadius ) ** 2 ) + ( ( $ oneRad * ( $ firstLongitude - $ secondLongitude ) * $ earthRadius * \ cos ( $ oneRad * ( $ firstLatitude + $ secondLatitude ) * .5 ) ) ** 2 ) ) , $ digits ) ; }
Calculate the spherical distance with the haversine formula.

@param float $firstLatitude   The first latitude coordinate.
@param float $firstLongitude  The first longitude coordinate.
@param float $secondLatitude  The second latitude coordinate.
@param float $secondLongitude The second longitude coordinate.
@param int   $digits          The number of digits after the decimal point.
@param int   $earthRadius     The earth radius.

@return float
Calculate the spherical distance with the haversine formula .