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

# nearestLocations

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

## Description

Returns an array of locations of chosen type(s) within the given radius of the given position, sorted from nearest to farthest.

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

## Syntax

```sqf
nearestLocations [centre, locationTypes, radius, sortPosition]
```

**Parameters:**

- `centre`: [Position2D](../topics/Position.md#introduction), [Position3D](../topics/Position.md#introduction) or [Object](../topics/Object.md)
- `locationTypes`: [Array](../topics/Array.md) of [String](../topics/String.md)s - list of [location type](../topics/Location.md#location-types) names, e.g "NameCity"; Arma 3 v2.14 passing empty array [] will return all available locations within the radius
- `radius`: [Number](../topics/Number.md) - maximum distance from the given position that returned locations may be, in metres
- `sortPosition`: [Position2D](../topics/Position.md#introduction), [Position3D](../topics/Position.md#introduction) or [Object](../topics/Object.md) - (Optional) results will be sorted from the distance to given *sortPosition* (nearest to farthest still)

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

## Examples

### Example 1

```sqf
_nearbyLocations = nearestLocations [getPosATL player, ["RockArea", "VegetationFir"], 100];
```

### Example 2

Find any of nearest locations:

```sqf
private _allLocationTypes = [];
"_allLocationTypes pushBack configName _x" configClasses (configFile >> "CfgLocationTypes");
{
    systemChat format [
        "%1 (%2) - %3m", 
        _x, 
        text _x, 
        getPosATL player distance _x
    ];
} forEach nearestLocations [player, _allLocationTypes, 500];
```

## See also

[createLocation](../commands/createLocation.md) · [nearestLocation](../commands/nearestLocation.md) · [locationPosition](../commands/locationPosition.md) · [nearestLocationWithDubbing](../commands/nearestLocationWithDubbing.md)

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