georadiusbymember #
Returns the members (added with geoadd) of a given key inside the provided geospatial radius, centered around one of a key's member.
Arguments #
georadiusbymember(key, geopoint, dist, unit, [options]);
Arguments | Type | Description |
---|---|---|
key | string | Key |
geopoint | string | Name of the geopoint to use as the center |
dist | number | Distance from the center |
unit | string | Unit of the distance parameter value. Allowed values: m , km , mi , ft |
options | object | Optional query arguments |
options #
The options
arguments can contain the following option properties:
Property | Type (default) | Description |
---|---|---|
count | integer | Limit the number of returned geopoints to the provided value |
queuable | boolean (true) | If true, queues the request during downtime, until connected to Kuzzle again |
sort | string | Sort the result by distance, relative to the center. Allowed values: ASC , DESC |
withcoord | boolean (false) | Include the position of the matched geopoint in the result |
withdist | boolean (false) | Include the calculated distance from the matched geopoint to center |
Resolve #
Resolves to an array of matched geopoints.
Each returned geopoint is an object with the following properties:
Property | Type | Description |
---|---|---|
name | string | Geopoint identifier |
coordinates | number[] | Geopoint coordinates in the following format: [lon, lat] . Only available if the option withcoord is set |
distance | number | Distance from the center. Only available if the option withdist is set |
Usage #
const kuzzleHQ = {
lon: 3.9109057,
lat: 43.6073913,
name: 'HQ'
};
const otherHQ = {
lon: 3.897105,
lat: 43.6002203,
name: 'other HQ'
};
try {
await kuzzle.ms.geoadd('geofoo', [kuzzleHQ, otherHQ]);
// Prints: [ { name: 'other HQ' }, { name: 'HQ' } ]
console.log(await kuzzle.ms.georadiusbymember(
'geofoo',
'HQ',
1500,
'm'
));
// Prints:
// [
// { name: 'other HQ', distance: 1367.8521 },
// { name: 'HQ', distance: 0 }
// ]
console.log(await kuzzle.ms.georadiusbymember(
'geofoo',
'HQ',
1500,
'm',
{withdist: true, sort: 'desc'}
));
// Prints:
// [
// {
// name: 'HQ',
// distance: 0,
// coordinates: [ 3.910904824733734, 43.607392252329916 ]
// },
// {
// name: 'other HQ',
// distance: 1367.8521,
// coordinates: [ 3.8971075415611267, 43.600221526170145 ]
// }
// ]
console.log(await kuzzle.ms.georadiusbymember(
'geofoo',
'HQ',
1500,
'm',
{withcoord: true, withdist: true, sort: 'asc'}
));
} catch (error) {
console.error(error.message);
}
Edit this page on Github(opens new window)