These snakes are known to be territorial, and if they feel threatened by a perceived predator (humans included), they may resort to spitting venom to deter them.
Spitting cobras can accurately aim their venom up to distances of 2-3 meters, which means that even standing in a safe space might not be enough to prevent a bite.