In reply to fergoid6:
I'll add a "plus 1" to the salt imbalance suggestions.
I used to get terrible cramps towards the end of a hill day, brought on by next to nothing. I tried taking "sports drinks" on the hill in addition to water but they didn't help.
I always craved salty snacks at the end of a day, and slowly realised that if I "gave in to temptation" the cramps subsided rather quickly. Since then I've started making up "hill fluid" with 50/50 apple juice and water, with about half a teaspoon of salt per litre added. "Sports drinks" usually contain very little, if any, salt.
The cramps seem to have gone for good. Now it may be in my case that it's the sodium and/or chloride imbalance that bring on the cramps, and in your case it might be a different element. I may also be better off sticking to water and taking very salty snacks with me, but this method works for me very well indeed.