src/Workout/TrackPoint.php
public function distanceFromPoint(TrackPoint $trackPoint): float
    {
        $earthRadius = 6371000;

        $latFrom = deg2rad($this->latitude());
        $lonFrom = deg2rad($this->longitude());
        $latTo = deg2rad($trackPoint->latitude());
        $lonTo = deg2rad($trackPoint->longitude());

        $latDelta = $latTo - $latFrom;
        $lonDelta = $lonTo - $lonFrom;

        $angle = 2 * asin(
                sqrt(
                    pow(sin($latDelta / 2), 2) +
                    cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)
                )
            );

        return $angle * $earthRadius;
    }
public function distanceFromPoint(TrackPoint $trackPoint): float
    {
        $earthRadius = 6371000;

        $latFrom = deg2rad($this->latitude());
        $lonFrom = deg2rad($this->longitude());
        $latTo = deg2rad($trackPoint->latitude());
        $lonTo = deg2rad($trackPoint->longitude());

        $latDelta = $latTo - $latFrom;
        $lonDelta = $lonTo - $lonFrom;

        $angle = 2 * asin(
                sqrt(
                    pow(sin($latDelta / 2), 2) +
                    cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)
                )
            );

        return $angle * $earthRadius;
    }
public function distanceFromPoint ( TrackPoint $ trackPoint ) : float { $ earthRadius = 6371000 ; $ latFrom = deg2rad ( $ this -> latitude ( ) ) ; $ lonFrom = deg2rad ( $ this -> longitude ( ) ) ; $ latTo = deg2rad ( $ trackPoint -> latitude ( ) ) ; $ lonTo = deg2rad ( $ trackPoint -> longitude ( ) ) ; $ latDelta = $ latTo - $ latFrom ; $ lonDelta = $ lonTo - $ lonFrom ; $ angle = 2 * asin ( sqrt ( pow ( sin ( $ latDelta / 2 ) , 2 ) + cos ( $ latFrom ) * cos ( $ latTo ) * pow ( sin ( $ lonDelta / 2 ) , 2 ) ) ) ; return $ angle * $ earthRadius ; }
Get the distance between this point and another point in meters.

@param TrackPoint $trackPoint The other point.
@return float The distance in meters.
Get the distance between this point and another point in meters .