Magnemite is found in Route 222, specifically the Fuego Ironworks by swarm. If you go to your rival's house in Sandgem and talk to their sister, she will tell you that there is an increase of Pokémon in a certain route or area. the swarm changes daily. You'd just have to wait until she mentions Magnemite is swarming and go catch one. If you want to see some other swarm Pokemon you can catch, then refer to this.