A doctor I'm not, but I have gotten these types of cramps in the past, they've brought tears to my eyes. I've been told it's from two reasons, lack hydration and potassium.
I am now drinking twice as much water as I used too, especially when I ride. I also have at least one bananna a day.
Do not know if this will help but it seems to work for me.