public function calculateDistanceInKilometers(
        \Tx_Oelib_Interface_Geo $object1,
        \Tx_Oelib_Interface_Geo $object2
    ) {
        if ($object1->hasGeoError()) {
            throw new \InvalidArgumentException('$object1 has a geo error.');
        }
        if ($object2->hasGeoError()) {
            throw new \InvalidArgumentException('$object2 has a geo error.');
        }
        if (!$object1->hasGeoCoordinates()) {
            throw new \InvalidArgumentException(
                '$object1 needs to have coordinates, but has none.'
            );
        }
        if (!$object2->hasGeoCoordinates()) {
            throw new \InvalidArgumentException(
                '$object2 needs to have coordinates, but has none.'
            );
        }

        $coordinates1 = $object1->getGeoCoordinates();
        $latitude1 = \deg2rad($coordinates1['latitude']);
        $longitude1 = \deg2rad($coordinates1['longitude']);
        $coordinates2 = $object2->getGeoCoordinates();
        $latitude2 = \deg2rad($coordinates2['latitude']);
        $longitude2 = \deg2rad($coordinates2['longitude']);

        return \acos(
                \sin($latitude1) * \sin($latitude2)
                + \cos($latitude1) * \cos($latitude2) * \cos($longitude2 - $longitude1)
            ) * self::EARTH_RADIUS_IN_KILOMETERS;
    }
public function calculateDistanceInKilometers(
        \Tx_Oelib_Interface_Geo $object1,
        \Tx_Oelib_Interface_Geo $object2
    ) {
        if ($object1->hasGeoError()) {
            throw new \InvalidArgumentException('$object1 has a geo error.');
        }
        if ($object2->hasGeoError()) {
            throw new \InvalidArgumentException('$object2 has a geo error.');
        }
        if (!$object1->hasGeoCoordinates()) {
            throw new \InvalidArgumentException(
                '$object1 needs to have coordinates, but has none.'
            );
        }
        if (!$object2->hasGeoCoordinates()) {
            throw new \InvalidArgumentException(
                '$object2 needs to have coordinates, but has none.'
            );
        }

        $coordinates1 = $object1->getGeoCoordinates();
        $latitude1 = \deg2rad($coordinates1['latitude']);
        $longitude1 = \deg2rad($coordinates1['longitude']);
        $coordinates2 = $object2->getGeoCoordinates();
        $latitude2 = \deg2rad($coordinates2['latitude']);
        $longitude2 = \deg2rad($coordinates2['longitude']);

        return \acos(
                \sin($latitude1) * \sin($latitude2)
                + \cos($latitude1) * \cos($latitude2) * \cos($longitude2 - $longitude1)
            ) * self::EARTH_RADIUS_IN_KILOMETERS;
    }
public function calculateDistanceInKilometers ( \ Tx_Oelib_Interface_Geo $ object1 , \ Tx_Oelib_Interface_Geo $ object2 ) { if ( $ object1 -> hasGeoError ( ) ) { throw new \ InvalidArgumentException ( '$object1 has a geo error.' ) ; } if ( $ object2 -> hasGeoError ( ) ) { throw new \ InvalidArgumentException ( '$object2 has a geo error.' ) ; } if ( ! $ object1 -> hasGeoCoordinates ( ) ) { throw new \ InvalidArgumentException ( '$object1 needs to have coordinates, but has none.' ) ; } if ( ! $ object2 -> hasGeoCoordinates ( ) ) { throw new \ InvalidArgumentException ( '$object2 needs to have coordinates, but has none.' ) ; } $ coordinates1 = $ object1 -> getGeoCoordinates ( ) ; $ latitude1 = \ deg2rad ( $ coordinates1 [ 'latitude' ] ) ; $ longitude1 = \ deg2rad ( $ coordinates1 [ 'longitude' ] ) ; $ coordinates2 = $ object2 -> getGeoCoordinates ( ) ; $ latitude2 = \ deg2rad ( $ coordinates2 [ 'latitude' ] ) ; $ longitude2 = \ deg2rad ( $ coordinates2 [ 'longitude' ] ) ; return \ acos ( \ sin ( $ latitude1 ) * \ sin ( $ latitude2 ) + \ cos ( $ latitude1 ) * \ cos ( $ latitude2 ) * \ cos ( $ longitude2 - $ longitude1 ) ) * self :: EARTH_RADIUS_IN_KILOMETERS ; }
Calculates the great-circle distance in kilometers between two geo
objects using the haversine formula.

@param \Tx_Oelib_Interface_Geo $object1
the first object, must have geo coordinates
@param \Tx_Oelib_Interface_Geo $object2
the second object, must have geo coordinates

@return float the distance between $object1 and $object2 in kilometers, will be >= 0.0

@throws \InvalidArgumentException
Calculates the great - circle distance in kilometers between two geo objects using the haversine formula .