The prepositions translates differently in different contexts. It is one of the really difficult things to get correct for non native speakers. You just have to remember which goes where.
You can say drikker kaffe i en kafé for this one, and be correct. But the set phrase for going out with friends to a café and drinking coffee (and maybe something to eat) is gå på kafé hence drikker kaffe på en kafé as the preferred translation.
Having a preposition mean both on and in seems so broad. Does på more directly translate to the English "on", but can just idiomatically express that you're "on site". (Similar to how sayings like "on my way" in English are more idiomatic then literal).