This seems to be a mountain view exception.
FWIW I agree; I can't think of a place I'd like to work less than the bay area. There's no good option for living there, let alone commuting.
For smaller offices it makes sense to have them in the middle of the city, for something as large as their Mountain View office, it'd be a huge mess inside a city for someone of that scale.
And you're forgetting the fact that the headquarter has been growing naturally over the years, so if they had indeed started in a city, they would've probably had a really hard time expanding.