You can remember the meaning of 公里 with this easy mnemonic:
In two kilometers you'll see the public (公) restroom of our village (里).
Using mnemonics to remember the meaning of Chinese characters like can have an enormous impact on how long to learn Mandarin it takes.