Genetic variation and population sizes are critical factors for successful adaptation to novel environmental conditions. Gene flow between sub-populations is a potent mechanism to provide such variation and can hence facilitate adaptation, for instance by increasing genetic variation or via the introduction of beneficial variants. On the other hand, if gene flow between different habitats is too strong, locally beneficial alleles may not be able to establish permanently. In the context of evolutionary rescue, intermediate levels of gene flow are therefore often optimal for maximizing a species chance for survival in metapopulations without spatial structure. To which extent and under which conditions gene flow facilitates or hinders evolutionary rescue in spatially structured populations remains unresolved. We address this question by studying the differences between evolutionary rescue in the island model and in the stepping stone model in a gradually deteriorating habitat. We show that evolutionary rescue is modulated by the rate of gene flow between different habitats, which in turn depends strongly on the spatial structure and the pattern of environmental deterioration. We use these insights to show that in many cases spatially structured models can be translated into a simpler island model using an appropriately scaled effective migration rate.