We present a calculation of the Sun's motion through the Milky Way over the last 500 million yr. The integration is based on estimates of the Sun's current position and speed from measurements with Hipparcos and on a realistic model for the Galactic gravitational potential. We estimate the times of the Sun's past spiral arm crossings for a range of assumed values of the spiral pattern angular speed. We find that for a difference between the mean solar and pattern speed of Ωsolar-Ωp=11.9+/-0.7 km s-1 kpc-1, the Sun has traversed four spiral arms at times that appear to correspond well with long-duration cold periods on Earth. This supports the idea that extended exposure to the higher cosmic-ray flux associated with spiral arms can lead to increased cloud cover and long ice age epochs on Earth.