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

nearSphere() public method

A GeoJSON point may be provided as the first and only argument for 2dsphere queries. This single parameter may be a GeoJSON point object or an array corresponding to the point's JSON representation.
See also: Builder::nearSphere()
See also: http://docs.mongodb.org/manual/reference/operator/nearSphere/
public nearSphere ( float | array | GeoJson\Geometry\Point $x, float $y = null )
$x float | array | GeoJson\Geometry\Point
$y float
    public function nearSphere($x, $y = null)
    {
        if ($x instanceof Point) {
            $x = $x->jsonSerialize();
        }
        if (is_array($x)) {
            return $this->operator('$nearSphere', ['$geometry' => $x]);
        }
        return $this->operator('$nearSphere', [$x, $y]);
    }

Usage Example

Example #1
0
 public function testMaxDistanceWithNearSphereAndLegacyCoordinates()
 {
     $expr = new Expr();
     $expr->nearSphere(1, 2);
     $this->assertSame($expr, $expr->maxDistance(1));
     $this->assertEquals(array('$nearSphere' => array(1, 2), '$maxDistance' => 1), $expr->getQuery());
 }
All Usage Examples Of Doctrine\MongoDB\Query\Expr::nearSphere