Carrot reference
Functions

nearestLocation()

Returns the nearest geographic Location to a particular person, group, or address.

Syntax

nearestLocation(entity[, list])

Parameters

Parameter

Type

Description

entity

Person, Group, or Address

The starting point to measure distance from

list

List

Optionally, a list of groups, addresses, or persons, to compare against. The one that is the nearest geographically will be returned.

If this parameter is not provided, all Locations will be compared.

Return Type

Person, Group, or Address

Whichever entity provided in the list, or whichever Group Location is closest geographically, will be returned.

Examples

nearestLocation(person)

Returns the nearest Location Group to the person, inclusive of remote locations and offices.

nearestLocation(person, person.managers)

Returns which of the person's manager chain lives closest to the person.

nearestLocation(person, db.group.find{type:location and name:atlanta,boston,orlando})

Returns which of the locations matching "Atlanta", "Boston" or "Orlando" is closest to the current person.