I used to have a great deal of trouble with leg cramps but then I discovered something very interesting. The cramps seem to be hung up energy. I say this because here is the solution I came up with and I am no longer bothered by leg cramps.
When the cramps start I immediately focus my attention on my heel and imagine energy flowing from the cramp to my heel. I then move my attention until I perceive the energy flowing out my toes. If I do this right the leg cramp is gone in a matter of seconds. It is not as easy as it sounds but once you get the hang of it you can get rid of leg cramps in short order.
Now this doesn't handle why you got the cramp in the first place that would have to be a separate handling but this does mean that you don't have to suffer the pain of a leg cramp for more than a second or 2.