Paradox/toolbox/Finder.php
public function findOneWithin($type, $reference, $radius, $aql, $params = array(), $placeholder = "doc")
    {
        $coordinates = $this->generateReferenceData($reference);

        $collectionParameter = $this->_toolbox->generateBindingParameter('@collection', $params);
        $latitudeParameter = $this->_toolbox->generateBindingParameter('latitude', $params);
        $longitudeParameter = $this->_toolbox->generateBindingParameter('longitude', $params);
        $radiusParameter = $this->_toolbox->generateBindingParameter('radius', $params);

        //If a AModel is passed in, we do not want the pod to be included in the results.
        if ($reference instanceof AModel) {
            //Prevent clashes with the paradox filter id parameter
            $filterParameter = $this->_toolbox->generateBindingParameter('paradox_filter_id', $params);

            //Filter out this pod.
            $query = "FOR $placeholder in WITHIN(@$collectionParameter, @$latitudeParameter, @$longitudeParameter, @$radiusParameter, '_paradox_distance_parameter') FILTER $placeholder._id != @$filterParameter FILTER " . $aql . " LIMIT 1 return $placeholder";

            $params[$filterParameter] = $reference->getPod()->getId();

        } else {
            $query = "FOR $placeholder in WITHIN(@$collectionParameter, @$latitudeParameter, @$longitudeParameter, @$radiusParameter, '_paradox_distance_parameter') FILTER " . $aql . " LIMIT 1 return $placeholder";
        }

        $params[$collectionParameter] = $this->getCollectionName($type);
        $params[$latitudeParameter] = $coordinates['latitude'];
        $params[$longitudeParameter] = $coordinates['longitude'];
        $params[$radiusParameter] = $radius;

        if ($this->_toolbox->getTransactionManager()->hasTransaction()) {
            $this->_toolbox->getTransactionManager()->addReadCollection($type);
            $statement = json_encode(array('query' => $query, 'bindVars' => $params), JSON_FORCE_OBJECT);
            $this->_toolbox->getTransactionManager()->addCommand("function () {var elements = db._createStatement($statement).execute().elements(); return elements[0] ? elements[0] : null}();", "Finder:findOneWithin", null, false, array('type' => $type, 'coordinates' => $coordinates));

        } else {
            try {
                $result = $this->_toolbox->getQuery()->getOne($query, $params);
            } catch (\Exception $e) {
                $normalised = $this->_toolbox->normaliseDriverExceptions($e);
                throw new FinderException($normalised['message'], $normalised['code']);
            }

            if (!$result) {
                return null;
            } else {
                $converted = $this->convertToPods($type, array($result), $coordinates);

                return reset($converted);
            }
        }
    }
public function findOneWithin($type, $reference, $radius, $aql, $params = array(), $placeholder = "doc")
    {
        $coordinates = $this->generateReferenceData($reference);

        $collectionParameter = $this->_toolbox->generateBindingParameter('@collection', $params);
        $latitudeParameter = $this->_toolbox->generateBindingParameter('latitude', $params);
        $longitudeParameter = $this->_toolbox->generateBindingParameter('longitude', $params);
        $radiusParameter = $this->_toolbox->generateBindingParameter('radius', $params);

        //If a AModel is passed in, we do not want the pod to be included in the results.
        if ($reference instanceof AModel) {
            //Prevent clashes with the paradox filter id parameter
            $filterParameter = $this->_toolbox->generateBindingParameter('paradox_filter_id', $params);

            //Filter out this pod.
            $query = "FOR $placeholder in WITHIN(@$collectionParameter, @$latitudeParameter, @$longitudeParameter, @$radiusParameter, '_paradox_distance_parameter') FILTER $placeholder._id != @$filterParameter FILTER " . $aql . " LIMIT 1 return $placeholder";

            $params[$filterParameter] = $reference->getPod()->getId();

        } else {
            $query = "FOR $placeholder in WITHIN(@$collectionParameter, @$latitudeParameter, @$longitudeParameter, @$radiusParameter, '_paradox_distance_parameter') FILTER " . $aql . " LIMIT 1 return $placeholder";
        }

        $params[$collectionParameter] = $this->getCollectionName($type);
        $params[$latitudeParameter] = $coordinates['latitude'];
        $params[$longitudeParameter] = $coordinates['longitude'];
        $params[$radiusParameter] = $radius;

        if ($this->_toolbox->getTransactionManager()->hasTransaction()) {
            $this->_toolbox->getTransactionManager()->addReadCollection($type);
            $statement = json_encode(array('query' => $query, 'bindVars' => $params), JSON_FORCE_OBJECT);
            $this->_toolbox->getTransactionManager()->addCommand("function () {var elements = db._createStatement($statement).execute().elements(); return elements[0] ? elements[0] : null}();", "Finder:findOneWithin", null, false, array('type' => $type, 'coordinates' => $coordinates));

        } else {
            try {
                $result = $this->_toolbox->getQuery()->getOne($query, $params);
            } catch (\Exception $e) {
                $normalised = $this->_toolbox->normaliseDriverExceptions($e);
                throw new FinderException($normalised['message'], $normalised['code']);
            }

            if (!$result) {
                return null;
            } else {
                $converted = $this->convertToPods($type, array($result), $coordinates);

                return reset($converted);
            }
        }
    }
Find one document/edge/verticeswithin a radius around the reference point. If nothing is found, null is returned.
A LIMIT 1 is automatically set, so you do not need to set the LIMIT yourself: doc.age > 20 SORT doc.name
If an AModel is passed in, the result array will not include the AModel that was passed in, even though it is within the coordinates.
@param  string       $type        The collection to search in. For graphs, only "vertex" and "edge" are allowed.
@param  AModel|array $reference   The reference point. This can be a model or an associative array containing latitude and longitude keys.
@param  float        $radius      The radius in meters.
@param  string       $aql         An AQL fragment that will be inserted after the FOR claus.
@param  array        $params      An optional associative array containing parameters to bind to the query.
@param  string       $placeholder Set this to something else if you do not wish to use "doc" to refer to documents in your query.
@return null|AModel