Endurance problems, fatigue, pain, etc can be personal and complicated. I find in general it is best to hit your body with fluids and electrolytes early and often. Eat before you feel hungry. Drink often. If you’re doing a long ride, you should be drinking a sports drink of some kind. High temperatures require a lot of drinking. I do a bottle an hour or more when it’s hot out (which requires me to know where all the water stops are).
If you don’t do long rides like that often, I’m not surprised you cramped up. That kind of stuff happens to me occasionally as well.