{"name":"nearestLocations","title":"nearestLocations","type":"command","url":"https://community.bistudio.com/wiki/nearestLocations","revid":377540,"updated":"2026-01-02T06:54:27Z","groups":["Locations"],"status":"ok","games":{"arma1":"1.08","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma1 1.08","arma3_since":"0.50","description":"Returns an array of locations of chosen type(s) within the given radius of the given position, sorted from nearest to farthest.\n\n> [!NOTE]\n> Although locations can be placed in 3D with setPosition, nearestLocations' search result is sorted in 2D.","syntaxes":[{"syntax":"nearestLocations [centre, locationTypes, radius, sortPosition]","params":[{"name":"centre","type":"Position2D, Position3D or Object","type_expr":"Position2D | Position3D | Object"},{"name":"locationTypes","type":"Array of Strings","description":"list of location type names, e.g \"NameCity\"; Arma 3 v2.14 passing empty array [] will return all available locations within the radius","type_expr":"Array<String>"},{"name":"radius","type":"Number","description":"maximum distance from the given position that returned locations may be, in metres","type_expr":"Number"},{"name":"sortPosition","type":"Position2D, Position3D or Object","optional":true,"description":"results will be sorted from the distance to given *sortPosition* (nearest to farthest still)","type_expr":"Position2D | Position3D | Object","text":"sortPosition: Position2D, Position3D or Object - (Optional) results will be sorted from the distance to given *sortPosition* (nearest to farthest still)"}],"returns":{"type":"Array of Locations","type_expr":"Array<Location>"},"form":"unary","right":{"text":"[centre, locationTypes, radius, sortPosition]"}}],"examples":[{"code":["_nearbyLocations = nearestLocations [getPosATL player, [\"RockArea\", \"VegetationFir\"], 100];"]},{"text":"Find any of nearest locations:\n\n```sqf\nprivate _allLocationTypes = [];\n\"_allLocationTypes pushBack configName _x\" configClasses (configFile >> \"CfgLocationTypes\");\n{\n    systemChat format [\n        \"%1 (%2) - %3m\",\n        _x,\n        text _x,\n        getPosATL player distance _x\n    ];\n} forEach nearestLocations [player, _allLocationTypes, 500];\n```","code":["private _allLocationTypes = [];\n\"_allLocationTypes pushBack configName _x\" configClasses (configFile >> \"CfgLocationTypes\");\n{\n\tsystemChat format [\n\t\t\"%1 (%2) - %3m\", \n\t\t_x, \n\t\ttext _x, \n\t\tgetPosATL player distance _x\n\t];\n} forEach nearestLocations [player, _allLocationTypes, 500];"]}],"see_also":["createLocation","nearestLocation","locationPosition","nearestLocationWithDubbing"]}