At versus In (She gave birth to twins at/in a hospital in the French Riviera.)

I still have difficulties to use at and in in many sentence.

Yesterday I see the news and there following:

She gave birth to twins at a hospital in the French Riviera.

Why at and why not in a hospital?

What is the rule that could make me easier to handle this two preposition?

She gave birth to twins at a hospital -> She gave birth to twins at a hospital not at home. (not at any place other than a hospital): one dimension or zero dimension (a dot on a map)
She gave birth to twins in a hospital -> She gave birth to twins under the roof of a hospital. (inside a hospital building): three dimensions.

Attila, there isn’t really much difference between using “at” and “in” in a sentence like that. You can interchange them depending on your mental picture of the event.

If you use “at a hospital”, you’re thinking more in terms of the activity that goes on at a hospital. “At” is often used when we’re focusing less on the place, and more on the activity. “In” is often used for presence in a place, without any thought to the activity that the place exists for.

You’re AT a post office to mail a package, but you might wait IN a post office for the rain to stop.

You usually eat, cook or wait tables AT a restaurant, but someone may get murdered IN a restaurant.

The difference is not very precise, so people interchange them quite a bit. We often say that someone is AT a hospital for the purpose of giving birth, having an operation, etc.