Sometimes, when hill walking, I have taken horrible, disabling cramp in my thigh muscles. I discovered that a drink of water with a tiny pinch of table salt provides a miraculous cure almost instantly. I assume that a lot of sweating leaves your body with a low sodium level.
The kind of cramp that twists and contorts your toes into weird shapes (especially when it's cold) seems to be a different beast altogether and can usually be overcome by stretches.