Em vs A: Location and Direction
Em expresses location (being in/at a place) while a expresses direction or a temporary arrival at a destination. The distinction is important for cities, buildings, and activities.
PortuStories Editorial
European Portuguese Grammar Guide
Em (contracting to no/na/nos/nas with definite articles) expresses location — being inside or at a place.
Moro em Lisboa.
I live in Lisbon.
Estou no café.
I am at/in the café.
A (contracting to ao/à/aos/às) expresses movement toward a destination or a brief, temporary presence at a specific point.
Vou à farmácia.
I am going to the pharmacy.
Movement toward destination.
Fui ao Porto no fim de semana.
I went to Porto at the weekend.
Movement to a city.
With cities, EP uses em for permanent residence (Vivo em Lisboa) and a for temporary visits (Fui a Lisboa). With countries taking a definite article, use em: no Brasil, na França.
From a PortuStories Story
Passei uma semana no Algarve e depois fui a Faro antes de voltar a Lisboa.
I spent a week in the Algarve and then went to Faro before returning to Lisbon.