There are several approaches to answer this question.
Ramban/Sifsei Chachamim
The Ramban says that ain hachi nami, Moshe did leave the city for the other makkos. However, by all the other makkos Moshe was able to wait until the next day to daven. By Barad, Pharoah wanted Moshe to daven right away. Moshe tehn had to explain to him that he had to first leave the city.
Da'as Zekainim
The Da'as Zekainim says that the avoda zara were the sheep. Until now all the sheep were outside the city limits. Before Barad, HKBH warned Mitzrayim to bring the animals into their houses or they would be killed. Consequently, all the sheep were now inside the city limits and Moshe had to leave the city to daven.
Netziv
The Netziv in his Shut Meishiv Davar (end of Chelek 1 Siman 10) writes that until now Moshe davened in his house. The house served as a mechitzah between Moshe and the avoda zara. Now that Moshe was davening outside he had no mechitza and had to leave the city.
Chevtzelas HaShoron
I also saw a teretz in the Chevtzelas HaShoron where he wants to distinguish between a bakasha and tefilla. Until now Moshe's davening was a bakasha but now it is a tefilla. Only tefilla has a problem of avoda zara. ayin sham to see his rayos and how he develops the mehalech.
Halacha L'Ma'aseh
How does this play out l'ma'aseh?
Terumas HaDeshen (Siman 6)
The Terumas Hadeshen discusses a case where someone is traveling. His two options for davening are either daven on the road or go to a non Jewish hotel that is full of idol worshippers. The Terumas HaDeshen answers that if one can daven on the road without anyone bothering him, he should daven on the road since the hotel will be full of avoda zara. He brings a rayah from MOshe Rabbeinu who went outside the city to daven. However, if he will be bothered on the road and he can fond a corner in the hotel in which he won't be disturbed , then he should daven in the the hotel. As far as the problem of davening among avoda zara, he says, since anyway our cities are filled with avoda zara it is okay to daven in the hotel.
Rema (Siman 94:9)
The Rema seems to bring this Terumas HaDeshen down l'halacha. However, as the Pri Megadim points out there is one major difference between the Terumas HaDeshen and the Rema. Whereas the Terumas HaDeshen is clearly concerned about davening among avoda zara, the Rema doesn't mention it at all. All the Rema says if you will not be disturbed on the road, then you should daven on the road since you will probably be disturbed in the hotel. He is not worried at all about avoda zara. It seems from the Rema that there is no issur to daven in a place filled with avoda zara.
Magan Avraham/Mishna Berura
The Magan Avraham however does bring down the reason of avoda zara. The Mishna Berura also brings it down. The Mishna Berura based on the Magein Geburim switches around a few words in the Rema in order that the Rema should be like the Terumas Hadeshen. He does add that you should daven in a different corner than the avoda zara even if it means not davening toward the east.
The way I understand the MIshna Berura is that if you can avoid davening in a room with avoda zara you should. But if you have no choice or your kavana will be disturbed it is mutar.
Hospital Rooms
A common shailah is daveing in a hospital room with avoda zara in it. I saw in the Piskei Teshuvos that he brings from the Atzei Chaim (Siman 1) and Chelek Levi that it is muttar. In fact the Cheelk Levi goes a step farther and says that if you work in such a building you don't have to leave to daven.
I would think based on the Mishna Berura it is also muttar. You can't be expected to leave the room and daven in the hallway. First of all if you are sick or just had a baby, your kavana would definately be better in the room. Second of all you will most probably be interrupted in the hallway and that is quivilant to the Terumas Hadeshen.
Building with two rooms
A case which I am not sure about is if you are in a hotel or building and the room you are in has avoda zara but another room doesn't. Furthermore, it is just as easy for you to go to one room over the other and noone will disturb you in either room, Would you be m'chuyav to switch rooms. On the one hand you do have the sevara that the whole city has avoda zara so what difference does it make which room you daven in. However, the mashmaos of the Terumas Hadeshen (and Mishna Berura) seems to be that l'chatchila you should avoid it if possible.