eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\MapLocationDistance::getBoundingCoordinates PHP Method

getBoundingCoordinates() protected method

Credits: http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates
protected getBoundingCoordinates ( eZ\Publish\API\Repository\Values\Content\Query\Criterion\Value\MapLocationValue $location, float $distance ) : array
$location eZ\Publish\API\Repository\Values\Content\Query\Criterion\Value\MapLocationValue
$distance float
return array
    protected function getBoundingCoordinates(MapLocationValue $location, $distance)
    {
        $radiansLatitude = deg2rad($location->latitude);
        $radiansLongitude = deg2rad($location->longitude);
        $angularDistance = $distance / self::EARTH_RADIUS;
        $deltaLongitude = asin(sin($angularDistance) / cos($radiansLatitude));
        $lowLatitudeRadians = $radiansLatitude - $angularDistance;
        $highLatitudeRadians = $radiansLatitude + $angularDistance;
        // Check that bounding box does not include poles.
        if ($lowLatitudeRadians > -M_PI_2 && $highLatitudeRadians < M_PI_2) {
            $boundingCoordinates = array('lowLatitude' => rad2deg($lowLatitudeRadians), 'lowLongitude' => rad2deg($radiansLongitude - $deltaLongitude), 'highLatitude' => rad2deg($highLatitudeRadians), 'highLongitude' => rad2deg($radiansLongitude + $deltaLongitude));
        } else {
            // Handle the pole(s) being inside a bounding box, in this case we MUST cover
            // full circle of Earth's longitude and one or both poles.
            // Note that calculation for distances over the polar regions with flat Earth formula
            // will be VERY imprecise.
            $boundingCoordinates = array('lowLatitude' => rad2deg(max($lowLatitudeRadians, -M_PI_2)), 'lowLongitude' => rad2deg(-M_PI), 'highLatitude' => rad2deg(min($highLatitudeRadians, M_PI_2)), 'highLongitude' => rad2deg(M_PI));
        }
        return $boundingCoordinates;
    }