He analyzed the traces that were left by the kids shoes and used them to realize which places the kids went to later. How could that work?
Sherlock wasn’t analysing the kids’ footprints, but the kidnappers’. From the scene where the footprints are analysed at the lab:
Sherlock opens container with footprint scratched from the school’s floor and uses tweezers to grab a piece. “Oil, John. The oil in the kidnapper’s footprint. It’ll lead us to Moriarty.” Drops piece into test tube with some chemical.
Sherlock obtains a sample from the test tube with a pipette. “All the chemical traces on his shoe have been preserved. The sole of the shoe is like a passport. If we’re lucky, we can see everything he’s been up to.“ Begins to look at sample under microscope.
It is entirely plausible that the kidnappers had already been at their hideout before performing the kidnapping.