---
title: nearestOffice()
slug: nearestoffice
docTags: 
createdAt: 2021-09-14T16:33:14.000Z
---

Returns the nearest geographic Location, including only Office locations (no Remote locations), to a particular person, group, or address.

### Syntax

`nearestOffice(entity[, list])`

### Parameters

| **Parameter** | **Type**                                                                                                                  | **Description**                                                                                                                                                                                                               |
| ------------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `entity`      | [Person](docId\:BZrX1MTDjk8CgkAW7UjQJ), [Group](docId:7kUM4sl_wT2Y_lDfMO6qb), or [Address](docId\:khI0D64Z7Evk0DsM_gJWf)  | The starting point to measure distance from                                                                                                                                                                                   |
| `list`        | [List](docId\:xWH_cUkHj9waqaEfb7H71)\<[Group](docId:7kUM4sl_wT2Y_lDfMO6qb)>                                               | (Optional) A list of Groups to compare against. The one that is the nearest geographically, and is also an Office, will be returned.<br />If this parameter is not provided, all Locations that are Offices will be compared. |

### Return Type

[Person](docId\:BZrX1MTDjk8CgkAW7UjQJ), [Group](docId:7kUM4sl_wT2Y_lDfMO6qb), or [Address](docId\:khI0D64Z7Evk0DsM_gJWf)

Whichever entity provided in the `list`, or whichever [Group](docId:7kUM4sl_wT2Y_lDfMO6qb) Location is closest geographically, will be returned.

### Examples

`nearestOffice(person)`

Returns the nearest Location, that is an office, to the person.

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

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