table.getNearest(point, {index: 'indexname'[, maxResults: 100, maxDist: 100000, unit: 'm', geoSystem: 'WGS84']}) → array
Return a list of documents closest to a specified point based on a geospatial index, sorted in order of increasing distance.
The index
argument is mandatory. Optional arguments are:
maxResults
: the maximum number of results to return (default 100).unit
: Unit for the distance. Possible values are m
(meter, the default), km
(kilometer), mi
(international mile), nm
(nautical mile), ft
(international foot).maxDist
: the maximum distance from an object to the specified point (default 100 km).geoSystem
: the reference ellipsoid to use for geographic coordinates. Possible values are WGS84
(the default), a common standard for Earth’s geometry, or unit_sphere
, a perfect sphere of 1 meter radius.The return value will be an array of two-item objects with the keys dist
and doc
, set to the distance between the specified point and the document (in the units specified with unit
, defaulting to meters) and the document itself, respectively. The array will be sorted by the values of dist
.
Example: Return a list of the closest 25 enemy hideouts to the secret base.
var secretBase = r.point(-122.422876,37.777128);
r.table('hideouts').getNearest(secretBase,
{index: 'location', maxResults: 25}
).run(conn, callback)
If you wish to find all points within a certain radius of another point, it’s often faster to use getIntersecting with circle, as long as the approximation of a circle that circle
generates is sufficient.
Couldn't find what you were looking for?
Contribute: edit this page or open an issue