For me, it varies with my mood. A lot of the time having some stress and interesting surroundings spurs my creativity and I've written some of my best code in a park, on an airplane or at a café. Other times I just want to lock myself in a familiar room with all my comforts and shut out the world.
That's why when I do the travel-and-work thing, I stay for 2-3 mo in a place, and I can mix things up depending on how I feel that week. I've also decided for myself that it's never a failure of travel to not be in local's dining room every night living the "real experience". I'm not on vacation, I'm still working, so I'll never see #2 as an issue.
But I would challenge the idea that complex programming problems (cloud sync, NLP, etc, choose your poison) can be solved equally well in a suboptimal environment. Here is my "hypothesis": unregulated noise, temperature, and other travel-centric environmental factors (such as the need for vigilance in a new environment) distract from cognitive performance in the majority of people, if not all people.
To be clear, I don't think it is possible to write my best code in a park, an airplane or a café, regardless of mood. But I would be curious to see relevant studies which demonstrate otherwise. I agree that changes in environment are stimulating and that stagnant workplaces hold their own dangers.
I also agree that 2-3 months is a good baseline for getting to know a place: you don't feel as jostled about by your schedule, and there may even be time for cursory grasp of the language (w/some prepping beforehand) and making a friend or two. Plus you don't have to cram your (potentially expensive) excursions into as short a block of time.