I just want to put my two cents out there albeit the fact there is a fantastic answer.
My Illogical Theory
I believe the gyms are based on the cities for a particular reason. The Gym Leader would have grown up around these Pokemon.
You know, if you lived in Humilau your entire life you would have been surrounded by Water Pokemon, and maybe even caught a few. That's how you met your Pokemon, because you were surrounded by them your entire life your only real choice was to train those type of Pokemon. Your parents wouldn't have let you go outside the city, they would have wanted you to stay there. Well, at least not far from the city anyway. They may have gone to close by areas such as Mt. Moon for little Brock to catch some Rock Pokemon, and maybe to Route 217 (I believe it is) for Snowpoint City Gym Leader Candice.
Of course, it would just seem weird to put a Fire-type Gym inside of Snowpoint City, so evidently the cities would be created first. But there's a bit of backstory if you care. Terlor remains correct though, so give him the credit if you wish.
Hope I helped. :)