---
title: nearestLocation()
slug: nearestlocation
docTags: 
createdAt: 2021-09-14T16:33:14.000Z
---

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

### Syntax

`nearestLocation(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)                                                                                      | Optionally, a list of groups, addresses, or persons, to compare against. The one that is the nearest geographically will be returned.<br />If this parameter is not provided, all Locations 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

`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.
