Doctrine\MongoDB\Query\Expr::maxDistance PHP Method

maxDistance() public method

This method must be called after near() or nearSphere(), since placement of the $maxDistance option depends on whether a GeoJSON point or legacy coordinates were provided for $near/$nearSphere.
See also: http://docs.mongodb.org/manual/reference/operator/maxDistance/
public maxDistance ( float $maxDistance )
$maxDistance float
    public function maxDistance($maxDistance)
    {
        if ($this->currentField) {
            $query =& $this->query[$this->currentField];
        } else {
            $query =& $this->query;
        }
        if (!isset($query['$near']) && !isset($query['$nearSphere'])) {
            throw new BadMethodCallException('This method requires a $near or $nearSphere operator (call near() or nearSphere() first)');
        }
        if (isset($query['$near']['$geometry'])) {
            $query['$near']['$maxDistance'] = $maxDistance;
        } elseif (isset($query['$nearSphere']['$geometry'])) {
            $query['$nearSphere']['$maxDistance'] = $maxDistance;
        } else {
            $query['$maxDistance'] = $maxDistance;
        }
        return $this;
    }

Usage Example

コード例 #1
0
ファイル: Builder.php プロジェクト: Wizkunde/mongodb
 /**
  * Set the "maxDistance" option for a geoNear command query or add
  * $maxDistance criteria to the query.
  *
  * If the query is a geoNear command ({@link Expr::geoNear()} was called),
  * the "maxDistance" command option will be set; otherwise, $maxDistance
  * will be added to the current expression.
  *
  * If the query uses GeoJSON points, $maxDistance will be interpreted in
  * meters. If legacy point coordinates are used, $maxDistance will be
  * interpreted in radians.
  *
  * @see Expr::maxDistance()
  * @see http://docs.mongodb.org/manual/reference/command/geoNear/
  * @see http://docs.mongodb.org/manual/reference/operator/maxDistance/
  * @see http://docs.mongodb.org/manual/reference/operator/near/
  * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/
  * @param float $maxDistance
  * @return self
  */
 public function maxDistance($maxDistance)
 {
     if ($this->query['type'] === Query::TYPE_GEO_NEAR) {
         $this->query['geoNear']['options']['maxDistance'] = $maxDistance;
     } else {
         $this->expr->maxDistance($maxDistance);
     }
     return $this;
 }
All Usage Examples Of Doctrine\MongoDB\Query\Expr::maxDistance