Possible answers to the first question:
- The biggest gap between two episodes set mainly on Earth is 36 - the nine four-part stories between City of Death and Logopolis. Even if we break that run for the Tardis's brief visit to Brighton in The Leisure Hive, that's still 23 consecutive Earth-free episodes.
- Close behind is the 22-episode, five-story interval between Image of the Fendahl and The Stones of Blood.
- There are 18 episodes between The Stones of Blood and City of Death.
- There are also 18 episodes between the second episode of The Three Doctors and The Green Death, if we don't count the Doctors' brief return to Earth after Omega is defeated.
- There are 16 episodes between Fury from the Deep and The Invasion (The Wheel In Space, The Dominators, The Mind Robber), and also between The Seeds of Death and Spearhead from Space (The Space Pirates, The War Games).
Possible answers to the second question:
- The first 39 episodes of the Pertwee era are basically set on contemporary Earth, though some of them on an alternate Earth and with some near-Earth space flight.
- The middle stories of Season 5, five six-parters with 30 episodes, are all set on our Earth with some hopping around in time (The Abominable Snowmen, The Ice Warriors, The Enemy of the World, The Web of Fear, Fury from the Deep).
There, aren't you glad you know that?