---
name: "nearestLocation"
type: command
status: ok
groups: ["Locations"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/nearestLocation
revid: 377409
updated: 2026-01-02T06:45:10Z
---

# nearestLocation

*Command · Locations · Arma 3 v0.50 · introduced in Armed Assault v1.08*

## Description

Return the closest location of specified class to a given position. Checked range is unlimited (i.e. covers the whole map).

> [!NOTE]
> Although locations can be placed in 3D with [setPosition](../commands/setPosition.md), [nearestLocations](../commands/nearestLocations.md) search is conducted in 2D.

## Syntax

```sqf
nearestLocation [position, locationType, maxDistance]
```

**Parameters:**

- `position`: [Object](../topics/Object.md) or [PositionAGL](../topics/Position.md#positionagl) or [Position2D](../topics/Position.md#introduction)
- `locationType`: [String](../topics/String.md) of a location class name. If "" is supplied, any nearest location is returned. Since Arma 3 2.14 locationType could be an [Array](../topics/Array.md) of location types. See [Location Types](../topics/Location.md#location-types)
- `maxDistance`: [Number](../topics/Number.md) - (Optional) max search radius. Default - unlimited range. *(since arma3 2.14)*

**Returns:** [Location](../topics/Location.md)

## Examples

### Example 1

```sqf
_nearestCity = nearestLocation [getPos player, "nameCity"];
```

### Example 2

```sqf
_anyNearestLocation = nearestLocation [player, ""];
```

## See also

[findNearestEnemy](../commands/findNearestEnemy.md) · [nearestBuilding](../commands/nearestBuilding.md) · [nearestObject](../commands/nearestObject.md) · [nearestObjects](../commands/nearestObjects.md) · [nearObjects](../commands/nearObjects.md) · [nearEntities](../commands/nearEntities.md) · [nearTargets](../commands/nearTargets.md) · [nearSupplies](../commands/nearSupplies.md) · [nearestLocationWithDubbing](../commands/nearestLocationWithDubbing.md) · [nearObjectsReady](../commands/nearObjectsReady.md) · [nearRoads](../commands/nearRoads.md) · [Location](../topics/Location.md) · [locationPosition](../commands/locationPosition.md) · [nearestLocations](../commands/nearestLocations.md) · [createLocation](../commands/createLocation.md) · [nearestMines](../commands/nearestMines.md)

<sub>Source: [BI Community Wiki — nearestLocation](https://community.bistudio.com/wiki/nearestLocation) (revision 377409).</sub>
