{"name":"nearestLocation","operator":null,"title":"nearestLocation","type":"command","url":"https://community.bistudio.com/wiki/nearestLocation","revid":377409,"updated":"2026-01-02T06:45:10Z","groups":["Locations"],"status":"ok","replaced_by":[],"games":[{"game":"arma1","name":"Armed Assault","version":"1.08"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma1","name":"Armed Assault","version":"1.08"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Return the closest location of specified class to a given position. Checked range is unlimited (i.e. covers the whole map).\n\n> [!NOTE]\n> Although locations can be placed in 3D with setPosition, nearestLocations search is conducted in 2D.","syntaxes":[{"syntax":"nearestLocation [position, locationType, maxDistance]","since":null,"effect":null,"exec":null,"params":[{"name":"position","type":"Object or PositionAGL or Position2D","optional":false,"default":null,"description":null,"types":["Object","PositionAGL","Position2D"],"since":null,"text":"position: Object or PositionAGL or Position2D"},{"name":"locationType","type":null,"optional":false,"default":null,"description":"String of a location class name. If \"\" is supplied, any nearest location is returned. Since Arma 3 2.14 locationType could be an Array of location types. See Location Types","types":["String","Array","Location Types"],"since":null,"text":"locationType: String of a location class name. If \"\" is supplied, any nearest location is returned. Since Arma 3 2.14 locationType could be an Array of location types. See Location Types"},{"name":"maxDistance","type":"Number","optional":true,"default":null,"description":"max search radius. Default - unlimited range.","types":["Number"],"since":"arma3 2.14","text":"maxDistance: Number - (Optional) max search radius. Default - unlimited range."}],"returns":{"type":"Location","types":["Location"],"description":null,"text":"Location"},"form":"unary","operator":null,"left":null,"right":{"text":"[position, locationType, maxDistance]","types":["Array"]}}],"examples":[{"text":"```sqf\n_nearestCity = nearestLocation [getPos player, \"nameCity\"];\n```","code":["_nearestCity = nearestLocation [getPos player, \"nameCity\"];"]},{"text":"```sqf\n_anyNearestLocation = nearestLocation [player, \"\"];\n```","code":["_anyNearestLocation = nearestLocation [player, \"\"];"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["findNearestEnemy","nearestBuilding","nearestObject","nearestObjects","nearObjects","nearEntities","nearTargets","nearSupplies","nearestLocationWithDubbing","nearObjectsReady","nearRoads","Location","locationPosition","nearestLocations","createLocation","nearestMines"],"notes":[],"categories":["ArmA: Armed Assault: New Scripting Commands","ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Locations","Introduced with Armed Assault version 1.08","Scripting Commands","Take On Helicopters: Scripting Commands"]}