Cramps are related to a few things, including how you eat and breathe.
-The best thing that you can do to avoid them, is to STRETCH before and after a run, especially a long one. This is the most important step in preventing cramps.
-Also you can hydrate well before a run as well as during and after. (Though you're supposed to hydrate all throughout the day) Bananas are a good source of potassium, which aid in preventing cramps.
-When you run, make sure that you are taking enough oxygen into your system, which means full breaths. Exhaling completely to allow for a new, full breath.
The most common causes of running cramps include lack of stretching and muscle fatigue. High temparatures, dehydration and loss of salts and electrolytes also contribute to running cramps. Your age also impacts your risk of cramps.
Those are the best steps I can give you in preventing running cramps.