georadius #
Returns the members (added with geoadd) of a given key inside the provided geospatial radius.
Arguments #
georadius(key, lon, lat, dist, unit, [options]);
Arguments | Type | Description |
---|---|---|
key | string | Key |
lon | number | Longitude of the center |
lat | number | Latitude of 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.georadius(
'geofoo',
3.948711,
43.5764455,
20,
'km'
));
// Prints:
// [
// { name: 'other HQ', distance: 4.9271 },
// { name: 'HQ', distance: 4.596 }
// ]
console.log(await kuzzle.ms.georadius(
'geofoo',
3.948711,
43.5764455,
20,
'km',
{withdist: true, sort: 'desc'}
));
// Prints:
// [
// {
// name: 'HQ',
// distance: 4.596,
// coordinates: [ 3.910904824733734, 43.607392252329916 ]
// },
// {
// name: 'other HQ',
// distance: 4.9271,
// coordinates: [ 3.8971075415611267, 43.600221526170145 ]
// }
// ]
console.log(await kuzzle.ms.georadius(
'geofoo',
3.948711,
43.5764455,
20,
'km',
{withcoord: true, withdist: true, sort: 'asc'}
));
} catch (error) {
console.error(error.message);
}
Edit this page on Github(opens new window)