Maggots are fly larvae. Flies lay eggs on food, then maggots hatch out of the fly eggs, then the maggots turn-into flies after eating, growing and molting. "Fly sticky traps" are available to buy. Hang these near your trashcan to trap most flies. Keep fly swatters near your trashcan, kill as many flies as possible. Buy trash bins with lids.