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( false ) | 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 ( | Include the position of the matched geopoint in the result |
withdist | boolean ( | Include the calculated distance from the matched geopoint to center |
timeout | number ( -1 ) | Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely |
triggerEvents | boolean ( false ) | If set to true , will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop. Available since Kuzzle 2.31.0 |
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)